class RequestContext:
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 |
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.
flask.session
pointing to an out-of-date object.Returns | |
RequestContext | Undocumented |
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.
exc
argument.Parameters | |
exc:t.Optional[ | Undocumented |
Undocumented
Parameters | |
exc_type:type | Undocumented |
exc_value:BaseException | Undocumented |
tb:TracebackType | Undocumented |
Undocumented
Parameters | |
app:Flask | Undocumented |
environ:dict | Undocumented |
request:t.Optional[ | Undocumented |
session:t.Optional[ | Undocumented |