8Flask的Request,Response的定制
Posted suren-apan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8Flask的Request,Response的定制相关的知识,希望对你有一定的参考价值。
Flask的Request,Response的定制
from flask import Flask
from flask import request
from flask import render_template
from flask import redirect
from flask import make_response
app = Flask(__name__)
#请求里面有哪些内容
#我们怎么定制响应
@app.route('/login.html', methods=['GET', "POST"])
def login():
# 请求相关信息
#提交的方法
print(request.method)
# request.args get请求提及的数据
print(request.args)
# request.form post请求提交的数据
# request.values post和get提交的数据总和
# request.cookies 客户端所带的cookie
# request.headers 请求头
print(request.headers)
# request.path 不带域名,请求路径
print(request.path)
# request.full_path 不带域名,带参数的请求路径
# request.script_root
# request.url 带域名带参数的请求路径
# request.base_url 带域名请求路径
# request.url_root 域名
# request.host_url 域名
# request.host 127.0.0.1:500
# request.files
# obj = request.files['the_file_name']
# obj.save('/var/www/uploads/' + secure_filename(f.filename))
# 响应相关信息
# return "字符串"
# return render_template('html模板路径',**{})
# return redirect('/index.html')
# return jsonify({'k1':'v1'})
#response = make_response(render_template('index.html'))
# response是flask.wrappers.Response类型
# response.delete_cookie('key')
# response.set_cookie('key', 'value')
# response.headers['X-Something'] = 'A value'
# return response
#1导入make_response
#2response=make_response(4剑客)
#3 操作response
# return response
response=make_response(render_template('index.html'))
response.set_cookie('jason', 'sb')
# response.delete_cookie('key')
response.headers['X-Something'] = 'A value sbwewewe'
return response
if __name__ == '__main__':
app.run()
以上是关于8Flask的Request,Response的定制的主要内容,如果未能解决你的问题,请参考以下文章
response.sendRedirect() 和 request.getRequestDispatcher().forward(request,response) 有啥区别 [重复]
response.sendRedirect(url)与request.getRequestDispatcher(url).forward(request,response)的区别
response.sendRedirect()和request.getRequestDispatcher().forward(request,response)使用
response.sendRedirect()和request.getRequestDispatcher().forward(request,response)的区别