3. Incoming Request Data

class flask.Request(environ, populate_request=True, shallow=False)[source]

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

It is what ends up as request. If you want to replace the request object used you can subclass this and set request_class to your subclass.

The request object is a Request subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones.


A MultiDict with the parsed form data from POST or PUT requests. Please keep in mind that file uploads will not end up here, but instead in the files attribute.


A MultiDict with the parsed contents of the query string. (The part in the URL after the question mark).


A CombinedMultiDict with the contents of both form and args.


A dict with the contents of all cookies transmitted with the request.


If the incoming form data was not encoded with a known mimetype the data is stored unmodified in this stream for consumption. Most of the time it is a better idea to use data which will give you that data as a string. The stream only returns the data once.


The incoming request headers as a dictionary like object.


Contains the incoming request data as string in case it came with a mimetype Flask does not handle.


A MultiDict with files uploaded as part of a POST or PUT request. Each file is stored as FileStorage object. It basically behaves like a standard file object you know from Python, with the difference that it also has a save() function that can store the file on the filesystem.


The underlying WSGI environment.


The current request method (POST, GET etc.)


Provides different ways to look at the current IRI. Imagine your application is listening on the following application root:


And a user requests the following URI:


In this case the values of the above mentioned attributes would be the following:

path u'/π/page.html'
full_path u'/π/page.html?x=y'
script_root u'/myapplication'
base_url u'http://www.example.com/myapplication/π/page.html'
url u'http://www.example.com/myapplication/π/page.html?x=y'
url_root u'http://www.example.com/myapplication/'

True if the request was triggered via a JavaScript XMLHttpRequest. This only works with libraries that support the X-Requested-With header and set it to XMLHttpRequest. Libraries that do that are prototype, jQuery and Mochikit and probably some more.


The name of the current blueprint


The endpoint that matched the request. This in combination with view_args can be used to reconstruct the same or a modified URL. If an exception happened when matching, this will be None.

get_json(force=False, silent=False, cache=True)[source]

Parses the incoming JSON request data and returns it. By default this function will return None if the mimetype is not application/json but this can be overridden by the force parameter. If parsing fails the on_json_loading_failed() method on the request object will be invoked.

  • force – if set to True the mimetype is ignored.
  • silent – if set to True this method will fail silently and return None.
  • cache – if set to True the parsed JSON data is remembered on the request.

Indicates if this request is JSON or not. By default a request is considered to include JSON data if the mimetype is application/json or application/*+json.

New in version 0.11.


If the mimetype is application/json this will contain the parsed JSON data. Otherwise this will be None.

The get_json() method should be used instead.


Read-only view of the MAX_CONTENT_LENGTH config key.


The name of the current module if the request was dispatched to an actual module. This is deprecated functionality, use blueprints instead.


Called if decoding of the JSON data failed. The return value of this method is used by get_json() when an error occurred. The default implementation just raises a BadRequest exception.

Changed in version 0.10: Removed buggy previous behavior of generating a random JSON response. If you want that behavior back you can trivially add it by subclassing.

New in version 0.8.

routing_exception = None

If matching the URL failed, this is the exception that will be raised / was raised as part of the request handling. This is usually a NotFound exception or something similar.

url_rule = None

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) etc.

New in version 0.6.

view_args = None

A dict of view arguments that matched the request. If an exception happened when matching, this will be None.

class flask.request

To access incoming request data, you can use the global request object. Flask parses incoming request data for you and gives you access to it through that global object. Internally Flask makes sure that you always get the correct data for the active thread if you are in a multithreaded environment.

This is a proxy. See Notes On Proxies for more information.

The request object is an instance of a Request subclass and provides all of the attributes Werkzeug defines. This just shows a quick overview of the most important ones.