flask 开发记录

from flask import request

判断method方式

request.method  'POST', ‘GET’

获取form内容

request.form['form_name']

获取url参数

(?key=value)  request.args.get('key', '')

request.args["url"]

获取上传的文件

确保在html表单中设置‘enctype="multipart/form-data"’属性,f = request.files['the_file'],   from werkzeug import secure_filename,  file_name = secure_filename(f.filename)

获取cookies内容

request.cookies.get('cook_name')

request.cookies['cook_name']

设置cookies内容

resp = make_response(render_template(...)) ,  rep.set_cookie('key', 'value')

---------------------------------------------------

res = app.make_response('hello lg')
res.set_cookie('username', value='lgphp', max_age=20000)

----------------------------------------------------------------------

删除cooikes

res = app.make_response(render_template(...))

res.delete_cookie('username')   也可以

res.set_cookie('username', value='lgphp', expires=0)

判断cookie存在?

if (request.cookies):

上一篇:HttpClient——连接关闭


下一篇:android:layout_weight属性详解