最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Flask后台如何获取PUT和POST接口传入的JSON参数数据

Flask crifan 1551浏览 0评论
在折腾Flask去实现一个后台期间,需要搞清楚,对于POST和PUT中,如何获取传递进来的json参数
flask get put parameter
python – How to get data received in Flask request – Stack Overflow
好像可以用:
data = request.data
dataDict = json.loads(data)
貌似可以直接用:
request.get_json()
即可?
python – How to obtain values of parameters of get request in flask? – Stack Overflow
web services – Python Flask how to get parameters from a URL? – Stack Overflow
去看官网:
http://flask.pocoo.org/docs/1.0/api/#flask.Request.data
data
Contains the incoming request data as string in case it came with a mimetype Werkzeug does not handle.
“get_json(force=False, silent=False, cache=True)
Parse and return the data as JSON. If the mimetype does not indicate JSON (application/json, seeis_json()), this returns None unless force is true. If parsing fails, on_json_loading_failed() is called and its return value is used as the return value.
Parameters:
* force – Ignore the mimetype and always try to parse JSON.
* silent – Silence parsing errors and return None instead.
* cache – Store the parsed JSON to return for subsequent calls.”
所以还是用get_json比较好用,注意调用接口时传入application/json就好

转载请注明:在路上 » 【已解决】Flask后台如何获取PUT和POST接口传入的JSON参数数据

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.209 seconds, using 22.15MB memory