Skip to main content

Request

The request object used by default in Flask. Remembers the matched endpoint and view arguments.

Attributes​

AttributeTypeDescription
json_modulet.Any = jsonThe JSON module used for handling JSON data within the request.
url_rule`RuleNone` = None
view_args`dict[str, t.Any]None` = None
routing_exception`HTTPExceptionNone` = None

Methods​


max_content_length()​

@classmethod
def max_content_length() - > int | None

The maximum number of bytes that will be read during this request. If this limit is exceeded, a 413 :exc:~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 :data: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.

Returns​

TypeDescription
`intNone`

max_content_length()​

@classmethod
def max_content_length(
value: int | None
) - > None

Sets the maximum number of bytes that will be read during this request. This allows for per-request configuration of the content length limit.

Parameters​

NameTypeDescription
value`intNone`

Returns​

TypeDescription
NoneNone

max_form_memory_size()​

@classmethod
def max_form_memory_size() - > int | None

The maximum size in bytes any non-file form field may be in a multipart/form-data body. If this limit is exceeded, a 413 :exc:~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 :data: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.

Returns​

TypeDescription
`intNone`

max_form_memory_size()​

@classmethod
def max_form_memory_size(
value: int | None
) - > None

Sets the maximum size in bytes for non-file form fields in a multipart/form-data body for this request. This allows for per-request configuration of the form memory limit.

Parameters​

NameTypeDescription
value`intNone`

Returns​

TypeDescription
NoneNone

max_form_parts()​

@classmethod
def max_form_parts() - > int | None

The maximum number of fields that may be present in a multipart/form-data body. If this limit is exceeded, a 413 :exc:~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 :data: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.

Returns​

TypeDescription
`intNone`

max_form_parts()​

@classmethod
def max_form_parts(
value: int | None
) - > None

Sets the maximum number of fields allowed in a multipart/form-data body for this request. This allows for per-request configuration of the form parts limit.

Parameters​

NameTypeDescription
value`intNone`

Returns​

TypeDescription
NoneNone

endpoint()​

@classmethod
def endpoint() - > str | None

The endpoint that matched the request URL. This will be None if matching failed or has not been performed yet. This in combination with :attr:view_args can be used to reconstruct the same URL or a modified URL.

Returns​

TypeDescription
`strNone`

blueprint()​

@classmethod
def blueprint() - > str | None

The registered name of the current blueprint. This will be 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.

Returns​

TypeDescription
`strNone`

blueprints()​

@classmethod
def blueprints() - > list[str]

The registered names of the current blueprint upwards through parent blueprints. This will be an empty list if there is no current blueprint, or if URL matching failed.

Returns​

TypeDescription
list[str]A list of strings representing the names of the current blueprint and its parent blueprints.

on_json_loading_failed()​

@classmethod
def on_json_loading_failed(
e: ValueError | None
) - > t.Any

Handles errors that occur during JSON loading. This method is called when JSON parsing fails, allowing for custom error handling or re-raising the exception.

Parameters​

NameTypeDescription
e`ValueErrorNone`

Returns​

TypeDescription
t.AnyThe result of the superclass's error handling, or raises a BadRequest exception.