1. 获取 request 数据
来源:https://stackoverflow.com/questions/10434599/get-the-data-received-in-a-flask-request
The docs describe the attributes available on the request object (from flask import request) during a request. In most common cases request.data will be empty because it's used as a fallback:
request.dataContains the incoming request data as string in case it came with a mimetype Flask does not handle.
request.args: the key/value pairs in the URL query stringrequest.form: the key/value pairs in the body, from a HTML post form, or JavaScript request that isn't JSON encodedrequest.files: the files in the body, which Flask keeps separate fromform. HTML forms must useenctype=multipart/form-dataor files will not be uploaded.request.values: combinedargsandform, preferringargsif keys overlaprequest.json: parsed JSON data. The request must have theapplication/jsoncontent type, or use -request.get_json(force=True)to ignore the content type.
All of these are MultiDict instances (except for json). You can access values using:
request.form['name']: use indexing if you know the key existsrequest.form.get('name'): usegetif the key might not existrequest.form.getlist('name'): usegetlistif the key is sent multiple times and you want a list of values.getonly returns the first value.request.urlThe full request URL with the scheme, host, root path, path, and query string.request.base_urlLike url but without the query string.
2. request 中的字段
来源:https://flask.palletsprojects.com/en/2.2.x/api/#flask.Request.json
很多……