前言
get请求参数是在URL里面的,post请求参数是放在请求头里面的
get请求:
python
@index_page.route("/get")
def get():
var_a = request.args.get("a", "jarvis")
return "request:%s,params:%s,var_a:%s" %(request.method,request.args,var_a)
浏览器访问 http://127.0.0.1:5000/get

自定义参数值,浏览器访问 http://127.0.0.1:5000/get?a=123

post请求
python
@index_page.route("/post", methods=["POST"])
def post():
var_a = request.form['a']
return "request:%s,params:%s,var_a:%s" % (request.method, request.form, var_a)
postman测试

使用reques.values同时获取get和post请求的参数:
python
@index_page.route("/get")
def get():
req = request.values
var_a = req['a'] if "a" in req else ""
return "request:%s,params:%s,var_a:%s" %(request.method,request.args,var_a)
@index_page.route("/post", methods=["POST"])
def post():
req = request.values
var_a = req['a'] if "a" in req else ""
return "request:%s,params:%s,var_a:%s" % (request.method, request.form, var_a)
这样的好处就是不用在代码里面区分get和post请求是用args和form来获取
思考:如果一个post请求里面有有共同的参数,这个时候会打印出什么呢?
验证:
可以看到打印出了get请求的参数值,GET优先级高于POST