werkzeug.BaseRequest

class werkzeug.BaseRequest(environ, populate_request=True, shallow=False)[source]

Very basic request object. This does not implement advanced stuff like entity tag parsing or cache controls. The request object is created with the WSGI environment as first argument and will add itself to the WSGI environment as 'werkzeug.request' unless it’s created with populate_request set to False.

There are a couple of mixins available that add additional functionality to the request object, there is also a class called Request which subclasses BaseRequest and all the important mixins.

It’s a good idea to create a custom subclass of the BaseRequest and add missing functionality either via mixins or direct implementation. Here an example for such subclasses:

from werkzeug.wrappers import BaseRequest, ETagRequestMixin

class Request(BaseRequest, ETagRequestMixin):
    pass

Request objects are read only. As of 0.5 modifications are not allowed in any place. Unlike the lower level parsing functions the request object will use immutable objects everywhere possible.

Per default the request object will assume all the text data is utf-8 encoded. Please refer to the unicode chapter for more details about customizing the behavior.

Per default the request object will be added to the WSGI environment as werkzeug.request to support the debugging system. If you don’t want that, set populate_request to False.

If shallow is True the environment is initialized as shallow object around the environ. Every operation that would modify the environ in any way (such as consuming form data) raises an exception unless the shallow attribute is explicitly set to False. This is useful for middlewares where you don’t want to consume the form data by accident. A shallow request is not populated to the WSGI environment.

Changed in version 0.5: read-only mode was enforced by using immutables classes for all data.

Methods

__init__(environ[, populate_request, shallow])
application(f) Decorate a function as responder that accepts the request as first argument.
close() Closes associated resources of this request object.
from_values(*args, **kwargs) Create a new request object based on the values provided.
get_data([cache, as_text, parse_form_data]) This reads the buffered incoming data from the client into one bytestring.
make_form_data_parser() Creates the form data parser.

Attributes

access_route If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server.
args The parsed URL parameters.
base_url Like url but without the querystring See also: trusted_hosts.
charset the charset for the request, defaults to utf-8
cookies Read only access to the retrieved cookie values as dictionary.
data
disable_data_descriptor Indicates whether the data descriptor should be allowed to read and buffer up the input stream.
encoding_errors the error handling procedure for errors, defaults to ‘replace’
files MultiDict object containing
form The form parameters.
full_path Requested path as unicode, including the query string.
headers The headers from the WSGI environ as immutable EnvironHeaders.
host Just the host including the port if available.
host_url Just the host with scheme as IRI.
input_stream
is_multiprocess boolean that is True if the application is served by
is_multithread boolean that is True if the application is served by
is_run_once boolean that is True if the application will be executed only
is_secure True if the request is secure.
is_xhr True if the request was triggered via a JavaScript XMLHttpRequest.
max_content_length the maximum content length. This is forwarded to the form data
max_form_memory_size the maximum form field size. This is forwarded to the form data
method The transmission method.
path Requested path as unicode.
query_string The URL parameters as raw bytestring.
remote_addr The remote address of the client.
remote_user If the server supports user authentication, and the script is protected, this attribute contains the username the user has authenticated as.
scheme URL scheme (http or https).
script_root The root path of the script without the trailing slash.
stream The stream to read incoming data from.
trusted_hosts Optionally a list of hosts that is trusted by this request.
url The reconstructed current URL as IRI.
url_charset The charset that is assumed for URLs.
url_root The full URL root (with hostname), this is the application root as IRI.
values Combined multi dict for args and form.
want_form_data_parsed Returns True if the request method carries content.