How to get data received in Flask request
我想能够将数据发送到我的烧瓶应用程序。我试过访问
1 2 3 4 | @app.route('/', methods=['GET', 'POST']) def parse_request(): data = request.data # data is empty # need posted data here |
这个问题的答案导致我在python flask中询问get raw post body,而不管接下来的内容类型是header,这是关于获取原始数据,而不是解析的数据。
(P)The docs describing the attributes available on the request.In most common cases EDOCX1 original 0 will be empty because it's used a s a fallback:(p)布尔奇1
- EDOCX1:The key/value pairs in the URL query string
- EDOCX1 2 enic:The key/value pairs in the body,from a html post form,or Javascript request that isn't json enceded
- EDOCX1 3:The files in the body,which flask keeps separate from EDOCX1 original 4.HTML Forms must use EDOCX1 penographic 5 common or files will not be uploaded.
- EDOCX1(英文)6:Combined EDOCX1(英文)7
(P)所有这些都是字母10You can access values using:(p)
- EDOCX1语言:如果你知道关键的成功,使用索引
- EDOCX1 12:使用EDOCX1,如果关键可能不存在
- EDOCX1 14:Use EDOCX1 English 15 if the key is sent multiple times and you want a list of values.EDOCX1 13,只有第一个值。
字母名称
(P)It is simply as follows(p)(P)For URL query parameter,use request.args(p)字母名称(P)For form input,use request.form(p)字母名称(P)数据类型应用/JSON,使用请求。(p)字母名称
(P)I give a full example of application/json:(p)字母名称(P)使用Postman for Post Request:(p)(P)字母名称(p)(P)使用Curl Command:(p)字母名称(P)P.S.For URL query parameter example,you can see my answer in multiple parameters in in in flask approve(p)
(P)Flask has another shortcut for JSon:(p)(P)队长:(p)字母名称
(P)如果你想要保留后的身体不受内容类型的约束,你应该使用字母名称17,因为字母名称2(p)
字母名称
(P)使用EDOCX1音标2。(p)(P)Instead of getting a single form data(EDOCX1 substances 26),you can obtain all posted data,by parsing the EDOCX1 substantial 27 communal provided by EDOCX1 substantial 2 palic object,like this:(p)(P)Flask(Route)(p)字母名称(P)壳牌(p)字母名称(P)For more details,this gist.(p)
(P)Simply speaking,you can get data by the way below:(p)字母名称(P)Now,EDOCX1 theocx1(英文)20 is an instance of EDOCX1(英文)19.They can use EDOCX1 English 20 which can handle most of your requirements.For example,you can use it just like this:(p)字母名称(P)Of course,you can use EDOCX1 penalty 23-Instead of EDOCX1(p)
字母名称(P)Now,data is the request body(p)
(P)如果我的类型被确认,他们将被发现的字母0和EDOCX1。(p)(P)为了得到全部的内容,你需要打电话(p)(P)See http://flask.pocoo.org/docs/1.0/api/.35;flask.request.get/.uu data(p)
字母名称(P)Get data if request type json and you can also mention default parameters along with it(p)字母名称(P)如果要求类型,请输入数据(p)字母名称(P)To fetch parameters from URL with a get request(p)
(P)In Javascript:(p)字母名称(P)In Python:(p)字母名称
(P)For those like me who have forgotten(a bit)about HTML,be sure EDOCX1 original 29 in your EDOCX1 music 30 welcx1 has a EDOCX1 nigital 31 welcribute!(p)字母名称(P)Result on console:(p)字母名称(P)不,不,不,不。(p)
(P)1.This is kind of a dirty hack to get all the request data regardless of how it was sent,but I seriously just use:(p)字母名称(P)and then I just return either a string that concates these,or,if I feel fancy,I skip the string calls/JSon dump and merge all the dictions.Then this can be logged,returned in a view function,whatever and you can actually see the whole request no matter what it includes.(p)
字母名称