If the body is recognized as form data, it will be in request.form
. If it's JSON, it will be in request.get_json()
. Otherwise the raw data will be in request.data
. If you're not sure how data will be submitted, you can use an or
chain to get the first one with data.
def get_request_data():
return (
request.args
or request.form
or request.get_json(force=True, silent=True)
or request.data
)
request.args
contains args parsed from the query string, regardless of what was in the body, so you would remove that from get_request_data()
if both it and a body should data at the same time.