flask之请求与响应
Posted 博
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()
响应稍后更新
以上是关于flask之请求与响应的主要内容,如果未能解决你的问题,请参考以下文章