improved _request_ctx_stack docs
This commit is contained in:
parent
bcd746e8cf
commit
9373a71c26
1 changed files with 30 additions and 0 deletions
30
docs/api.rst
30
docs/api.rst
|
|
@ -301,6 +301,36 @@ Useful Internals
|
||||||
instance and can be used by extensions and application code but the
|
instance and can be used by extensions and application code but the
|
||||||
use is discouraged in general.
|
use is discouraged in general.
|
||||||
|
|
||||||
|
The following attributes are always present on each layer of the
|
||||||
|
stack::
|
||||||
|
|
||||||
|
`app`
|
||||||
|
the active Flask application.
|
||||||
|
|
||||||
|
`url_adapter`
|
||||||
|
the URL adapter that was used to match the request.
|
||||||
|
|
||||||
|
`request`
|
||||||
|
the current request object.
|
||||||
|
|
||||||
|
`session`
|
||||||
|
the active session object.
|
||||||
|
|
||||||
|
`g`
|
||||||
|
an object with all the attributes of the :data:`flask.g` object.
|
||||||
|
|
||||||
|
`flashes`
|
||||||
|
an internal cache for the flashed messages.
|
||||||
|
|
||||||
|
Example usage::
|
||||||
|
|
||||||
|
from flask import _request_ctx_stack
|
||||||
|
|
||||||
|
def get_session():
|
||||||
|
ctx = _request_ctx_stack.top
|
||||||
|
if ctx is not None:
|
||||||
|
return ctx.session
|
||||||
|
|
||||||
.. versionchanged:: 0.4
|
.. versionchanged:: 0.4
|
||||||
|
|
||||||
The request context is automatically popped at the end of the request
|
The request context is automatically popped at the end of the request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue