flask之请求与响应

请求相关
1 from flask import Flask 2 from flask import request 3 from flask import render_template 4 from flask import redirect 5 from flask import make_response 6 7 app = Flask(__name__) 8 9 10 @app.route('/login.html', methods=['GET', "POST"]) 11 def login(): 12 13 # 请求相关信息 14 # request.method 15 # request.args 16 # request.form 17 # request.values 18 # request.cookies 19 # request.headers 20 # request.path 21 # request.full_path 22 # request.script_root 23 # request.url 24 # request.base_url 25 # request.url_root 26 # request.host_url 27 # request.host 28 # request.files 29 # obj = request.files['the_file_name'] 30 # obj.save('/var/www/uploads/' + secure_filename(f.filename)) 31 32 # 响应相关信息 33 # return "字符串" 34 # return render_template('html模板路径',**{}) 35 # return redirect('/index.html') 36 37 # response = make_response(render_template('index.html')) 38 # response是flask.wrappers.Response类型 39 # response.delete_cookie('key') 40 # response.set_cookie('key', 'value') 41 # response.headers['X-Something'] = 'A value' 42 # return response 43 44 45 return "内容" 46 47 if __name__ == '__main__': 48 app.run()

 

posted @ 2018-05-01 10:31  兰博~~  阅读(196)  评论(0编辑  收藏  举报