BASE_DIR = os.path.dirname(os.path.abspath(__file__)
SQLALCHEMY_DATABASE_URI = 'sqlite:////'+ os.path.join(BASE_DIR,'develop.db')
parser = reqparse.RequestParser()
- 普通参数
parser.add_argument('username', type=str, required=True, help='请提供用户名')
# token:user.id
cache.set(user.token, user.id, timeout=60)
userid = cache.get(token)
cache.delete(token)
generate_password_hash(password): 输入相同,但每次输出结果都是不一样的
check_password_hash(hash,password): 出入hash与输入的值比较是否相等
- 图片格式
parser.add_argument('headimg', type=werkzeug.datastructures.FileStorage, location='files',required=True, help='请选择图片')
- settings.py文件中
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'App/static/img/')
- 图片数据
imgfile = parse.get('headimg')
- 图片名称
secure_filename(imgFile.filename)
filename = '%d-%s' % (user.id,secure_filename(imgfile.filename))
- 图片路径
filepath = os.path.join(UPLOAD_FOLDER, filename)
- 保存文件
imgfile.save(filepath)
import json
import pymysql
# 数据库连接
db = pymysql.Connect(host='127.0.0.1',port=3306, user='root', password='1234', database='python1807tpp', charset='utf8')
# 游标
cursor = db.cursor()
# 打开文件,读取文件数据
with open('city.json', 'r') as f:
# 加载json
city_collection = json.load(f)
# 数据源
returnValue = city_collection['returnValue']
# 获取所有的key
letters = returnValue.keys()
# 遍历操作
for letter in letters:
# 存入数据库 letter
db.begin()
# INSERT INTO letter(name) VALUES(letter)
cursor.execute("INSERT INTO letter(name) VALUES('{}')".format(letter))
db.commit()
# 获取字母对应的城市
cities = returnValue[letter]
# 获取该字母对应的id 【插入城市数据时,需要指定是属于哪个字母 id】
db.begin()
# SELECT * FROM letter WHERE name=letter
cursor.execute("SELECT * FROM letter WHERE name='{}'".format(letter))
db.commit()
# 取出字母对应的id
letter_result = cursor.fetchone()
letter_id = letter_result[0]
# 遍历该字母对应的城市
for city in cities:
print(city)
db.begin()
# INSERT INTO city(id,cityCode, pinYin,regionName,c_letter) VALUES()
cursor.execute("INSERT INTO city(id,cityCode, pinYin,regionName,c_letter) VALUES('{}','{}','{}','{}','{}')".format(city['id'],city['cityCode'], city['pinYin'], city['regionName'], letter_id))
db.commit()
$.cookie(key, value, option)
$.cookie(key, {exprires:3, path:"/"})
获取cookie
$.cookie(key)
删除cookie
$.cookie(key, null)
网友评论