flask的请求与响应
flask的请求与响应
from flask import Flask, request, make_response, render_template, redirect
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
# 请求相关的信息
# print("请求方法",request.method)#请求方法
# print("get请求的参数",request.args)# get请求的参数
# print("post请求的参数",request.form) #post请求的参数
# print("post,与get的所有参数",request.values)#post,与get的所有参数
# print("请求的cookies",request.cookies)#请求的cookies
# 请求相关信息
# request.method 提交的方法
# request.args get请求提及的数据
# request.form post请求提交的数据
# request.values post和get提交的数据总和
# request.cookies 客户端所带的cookie
# request.headers 请求头
# 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))
# 关于响应我们已经了解了4剑客,那么如何添加响应头,以及cookie
# 要添加这些东西必须导入make_response
response = make_response('ok')
# 也可以在页面中设置
# response = make_response(render_template("login.html"))
# response = make_response(redirect("/login"))
# 设置cookie
response.set_cookie('key', 'val')
# 如何删除cookie
response.delete_cookie('key')
# 如何设置响应头
response.headers['alen-handsome'] = 'alkfkalj666'
return response
if __name__ == '__main__':
app.run()
Only you can control your future
You're not alone. You still have family,peopel who care for you and want to save you.