Python Flask Request Data | The Dev Tool | Toolel.com

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:


from flask import request

@app.route('/', methods=['GET', 'POST'])
def parse_request():
    # data is usuall empty
    data = request.data
    # Contains the incoming request data as string in case it came with a mimetype Flask does not handle.
    print(request.data)
    # the key/value pairs in the URL query string
    print(request.args)
    # the key/value pairs in the body, from a HTML post form, or JavaScript request that isn't JSON encoded
    print(request.form)
    # the files in the body, which Flask keeps separate from form. HTML forms must use  enctype=multipart/form-data or files will not be uploaded.
    print(request.files)
    # combined args and form, preferring args if keys overlap
    # parsed JSON data. The request must have the application/json content type, or use request.get_json(force=True) to ignore the content
    print(request.values)
    # Json of the request (only if Content type is Application/Json
    print(request.json)

Created by: Altin

Comments

This page is only partially working without JavaScript. It will show content, but the tools and interactivity cannot be shown without JavaScript enabled. Please enable JavaScript for this page. About Us