Request
The request object used by default in Flask. It is what ends up asflask.request. If you want to replace the request object used you can subclass this and set Flask.request_class to your subclass.
The request object is a werkzeug.wrappers.Request subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones.
Attributes
url_rule
The internal URL rule that matched the request. This can be useful to inspect which methods are allowed for the URL from a before/after handler (request.url_rule.methods). Though if the request’s method was invalid for the URL rule, the valid list is available in routing_exception.valid_methods instead (an attribute of the Werkzeug exception werkzeug.exceptions.MethodNotAllowed) because the request was never internally bound.
- Type:
Rule | None - Added in: 0.6
view_args
A dict of view arguments that matched the request. If an exception happened when matching, this will beNone.
- Type:
dict[str, Any] | None
routing_exception
If matching the URL failed, this is the exception that will be raised / was raised as part of the request handling. This is usually awerkzeug.exceptions.NotFound exception or something similar.
- Type:
HTTPException | None
Properties
max_content_length
werkzeug.exceptions.RequestEntityTooLarge error is raised. If it is set to None, no limit is enforced at the Flask application level. However, if it is None and the request has no Content-Length header and the WSGI server does not indicate that it terminates the stream, then no data is read to avoid an infinite stream.
Each request defaults to the MAX_CONTENT_LENGTH config, which defaults to None. It can be set on a specific request to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.
Changed in 3.1: This can be set per-request.
Changed in 0.6: This is configurable through Flask config.
max_form_memory_size
multipart/form-data body. If this limit is exceeded, a 413 werkzeug.exceptions.RequestEntityTooLarge error is raised. If it is set to None, no limit is enforced at the Flask application level.
Each request defaults to the MAX_FORM_MEMORY_SIZE config, which defaults to 500_000. It can be set on a specific request to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.
Changed in 3.1: This is configurable through Flask config.
max_form_parts
multipart/form-data body. If this limit is exceeded, a 413 werkzeug.exceptions.RequestEntityTooLarge error is raised. If it is set to None, no limit is enforced at the Flask application level.
Each request defaults to the MAX_FORM_PARTS config, which defaults to 1_000. It can be set on a specific request to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.
Changed in 3.1: This is configurable through Flask config.
endpoint
None if matching failed or has not been performed yet.
This in combination with view_args can be used to reconstruct the same URL or a modified URL.
blueprint
None if the endpoint is not part of a blueprint, or if URL matching failed or has not been performed yet.
This does not necessarily match the name the blueprint was created with. It may have been nested, or registered with a different name.
blueprints
Common Request Attributes (from Werkzeug)
The Flask Request object inherits from Werkzeug’s Request class and provides access to the following common attributes:Request Data
args
The parsed URL parameters (query string).form
The form parameters from POST or PUT requests.files
The uploaded files.data
The raw request body data as bytes.json
The parsed JSON data from the request body. ReturnsNone if the request doesn’t contain JSON data.
cookies
A dictionary of cookies sent with the request.Request Metadata
method
The HTTP method (GET, POST, PUT, DELETE, etc.).headers
The request headers.url
The full URL of the request.base_url
The URL without query string.path
The path portion of the URL.host
The host (domain) from the request.remote_addr
The IP address of the client.scheme
The URL scheme (http or https).is_secure
True if the request is over HTTPS.Methods
get_json()
Ignore the mimetype and always try to parse JSON
Return None instead of raising an error on parse failure
Cache the parsed JSON data
