Flask快速入门(6) — 常见的请求与响应参数
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.debug = True
@app.route('/', methods=['GET', "POST"])
def login():
# 请求相关信息
# request.method 提交请求的方法
print(request.method)
# request.args get请求提及的数据
print(request.args)
# request.form post请求提交的数据
print(request.form)
# request.values post和get提交的数据总和
print(request.values)
# request.cookies 客户端所带的cookie
print(request.cookies)
# request.headers 请求头
print(request.headers)
# request.path 不带域名,请求路径
print(request.path)
# request.full_path 不带域名,带参数的请求路径
print(request.full_path)
# request.script_root
print(request.script_root)
# request.url 带域名带参数的请求路径
print(request.url)
# request.base_url 带域名请求路径
print(request.base_url)
# request.url_root 域名
print(request.url_root)
# request.host_url 域名
print(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') 删除cookie
# response.set_cookie('key', 'value') 设置cookie
# response.headers['X-Something'] = 'A value' 设置响应头
# return response
return "内容"
if __name__ == '__main__':
app.run()