可以根据flask的request对象获取所有的请求信息
path = request.path # 获取请求地址
method = request.method # 获取请求方法
ip = request.remote_addr # 请求来源的ip
form = request.form # 获取form表单的数据
value = request.values # 获取查询字符串/表单数据
headers = request.headers # 后区头部信息
User_Agent = request.headers[‘User-Agent‘] # 获取发起请求的浏览器的信息
host = request.headers[‘Host‘] # 主机
name = request.args.get(‘name‘, "没有获取到name") # 获取指定参数
environ = request.environ # 环境
full_path = request.full_path # 完整路径
url = request.url
base_url = request.base_url
url_root = request.url_root
si_xhr = request.is_xhr # 是否为XMLHTTPRequest请求
blueprint = request.blueprint # 当前的蓝图名
endpoint = request.endpoint # 根节点, 当前执行的函数
view_args = request.view_args # 视图参数
name = request.args.get(‘name‘, "没有获取到name") # 获取指定参数
请求/rq/
# coding:utf-8from flask import Flask, request app = Flask(__name__) @app.route("/rq/")def get_request(): """ request数据 """ path = request.path # 获取请求地址 method = request.method # 获取请求方法 ip = request.remote_addr # 请求来源的ip form = request.form # 获取form表单的数据 value = request.values # 获取查询字符串/表单数据 headers = request.headers # 后区头部信息 User_Agent = request.headers[‘User-Agent‘] # 获取发起请求的浏览器的信息 host = request.headers[‘Host‘] # 主机 name = request.args.get(‘name‘, "没有获取到name") # 获取指定参数 environ = request.environ # 环境 full_path = request.full_path # 完整路径 url = request.url base_url = request.base_url url_root = request.url_root si_xhr = request.is_xhr # 是否为XMLHTTPRequest请求 blueprint = request.blueprint # 当前的蓝图名 endpoint = request.endpoint # 根节点, 当前执行的函数 view_args = request.view_args # 视图参数 name = request.args.get(‘name‘, "没有获取到name") # 获取指定参数 return User_Agent # 解码 if __name__ == ‘__main__‘: app.run(debug=True)
原文地址:https://www.cnblogs.com/zhongyehai/p/11442874.html