Implemented a separate application context.

This commit is contained in:
Armin Ronacher 2012-04-09 14:34:12 +01:00
parent a1305973bf
commit 47288231fe
3 changed files with 78 additions and 3 deletions

View file

@ -28,7 +28,7 @@ from .helpers import _PackageBoundObject, url_for, get_flashed_messages, \
find_package
from .wrappers import Request, Response
from .config import ConfigAttribute, Config
from .ctx import RequestContext
from .ctx import RequestContext, AppContext
from .globals import _request_ctx_stack, request
from .sessions import SecureCookieSessionInterface
from .module import blueprint_is_module
@ -1458,6 +1458,21 @@ class Flask(_PackageBoundObject):
return rv
request_tearing_down.send(self)
def app_context(self):
"""Binds the application only. For as long as the application is bound
to the current context the :data:`flask.current_app` points to that
application. An application context is automatically created when a
request context is pushed if necessary.
Example usage::
with app.app_context():
...
.. versionadded:: 0.9
"""
return AppContext(self)
def request_context(self, environ):
"""Creates a :class:`~flask.ctx.RequestContext` from the given
environment and binds it to the current context. This must be used in