class documentation

class RequestContext:

View In Hierarchy

The request context contains all request relevant information. It is created at the beginning of the request and pushed to the _request_ctx_stack and removed at the end of it. It will create the URL adapter and request object for the WSGI environment provided.

Do not attempt to use this class directly, instead use ~flask.Flask.test_request_context and ~flask.Flask.request_context to create this object.

When the request context is popped, it will evaluate all the functions registered on the application for teardown execution (~flask.Flask.teardown_request).

The request context is automatically popped at the end of the request for you. In debug mode the request context is kept around if exceptions happen so that interactive debuggers have a chance to introspect the data. With 0.4 this can also be forced for requests that did not fail and outside of DEBUG mode. By setting 'flask._preserve_context' to True on the WSGI environment the context will not pop itself at the end of the request. This is used by the ~flask.Flask.test_client for example to implement the deferred cleanup functionality.

You might find this helpful for unittests where you need the information from the context local around for a little longer. Make sure to properly ~werkzeug.LocalStack.pop the stack yourself in that situation, otherwise your unittests will leak memory.

Method copy No summary
Method match​_request Can be overridden by a subclass to hook into the matching of the request.
Method pop Pops the request context and unbinds it by doing that. This will also trigger the execution of functions registered by the ~flask.Flask.teardown_request decorator.
Method push Binds the request context to the current context.
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method auto​_pop Undocumented
Method g.setter Undocumented
Instance Variable ​_after​_request​_functions Undocumented
Instance Variable ​_implicit​_app​_ctx​_stack Undocumented
Instance Variable ​_preserved​_exc Undocumented
Instance Variable app Undocumented
Instance Variable flashes Undocumented
Instance Variable preserved Undocumented
Instance Variable request Undocumented
Instance Variable session Undocumented
Instance Variable url​_adapter Undocumented
Property g Undocumented
def copy(self):

Creates a copy of this request context with the same request object. This can be used to move a request context to a different greenlet. Because the actual request object is the same this cannot be used to move a request context to a different thread unless access to the request object is locked.

New in version 0.10.
Changed in version 1.1: The current session object is used instead of reloading the original data. This prevents flask.session pointing to an out-of-date object.
Returns
RequestContextUndocumented
def match_request(self):
Can be overridden by a subclass to hook into the matching of the request.
def pop(self, exc=_sentinel):

Pops the request context and unbinds it by doing that. This will also trigger the execution of functions registered by the ~flask.Flask.teardown_request decorator.

Changed in version 0.9: Added the exc argument.
Parameters
exc:t.Optional[BaseException]Undocumented
def push(self):
Binds the request context to the current context.
def __enter__(self):

Undocumented

Returns
RequestContextUndocumented
def __exit__(self, exc_type, exc_value, tb):

Undocumented

Parameters
exc​_type:typeUndocumented
exc​_value:BaseExceptionUndocumented
tb:TracebackTypeUndocumented
def __init__(self, app, environ, request=None, session=None):

Undocumented

Parameters
app:FlaskUndocumented
environ:dictUndocumented
request:t.Optional[Request]Undocumented
session:t.Optional[SessionMixin]Undocumented
def __repr__(self):

Undocumented

Returns
strUndocumented
def auto_pop(self, exc):

Undocumented

Parameters
exc:t.Optional[BaseException]Undocumented
@g.setter
def g(self, value):

Undocumented

Parameters
value:AppContextUndocumented
_after_request_functions: t.List[AfterRequestCallable] =

Undocumented

_implicit_app_ctx_stack: t.List[t.Optional[AppContext]] =

Undocumented

_preserved_exc =

Undocumented

app =

Undocumented

flashes =

Undocumented

preserved: bool =

Undocumented

request =

Undocumented

session =

Undocumented

url_adapter =

Undocumented

@property
g: AppContext =

Undocumented