Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated docs for the app context.

  • Loading branch information...
commit 0207e90155abe937568727e4e9eca949b8247cd5 1 parent f8f2e2d
@mitsuhiko authored
Showing with 28 additions and 1 deletion.
  1. +3 −0  CHANGES
  2. +15 −1 docs/api.rst
  3. +10 −0 flask/ctx.py
View
3  CHANGES
@@ -45,6 +45,9 @@ Relase date to be decided, codename to be chosen.
- The :meth:`flask.render_template` method now accepts a either an iterable of
template names or a single template name. Previously, it only accepted a
single template name. On an iterable, the first template found is rendered.
+- Added :meth:`flask.Flask.app_context` which works very similar to the
+ request context but only provides access to the current application. This
+ also adds support for URL generation without an active request context.
Version 0.8.1
View
16 docs/api.rst
@@ -265,12 +265,16 @@ Useful Functions and Classes
Points to the application handling the request. This is useful for
extensions that want to support multiple applications running side
- by side.
+ by side. This is powered by the application context and not by the
+ request context, so you can change the value of this proxy by
+ using the :meth:`~flask.Flask.app_context` method.
This is a proxy. See :ref:`notes-on-proxies` for more information.
.. autofunction:: has_request_context
+.. autofunction:: has_app_context
+
.. autofunction:: url_for
.. function:: abort(code)
@@ -412,6 +416,16 @@ Useful Internals
if ctx is not None:
return ctx.session
+.. autoclass:: flask.ctx.AppContext
+ :members:
+
+.. data:: _app_ctx_stack
+
+ Works similar to the request context but only binds the application.
+ This is mainly there for extensions to store data.
+
+ .. versionadded:: 0.9
+
.. autoclass:: flask.blueprints.BlueprintSetupState
:members:
View
10 flask/ctx.py
@@ -59,6 +59,16 @@ def __init__(self, username, remote_addr=None):
return _request_ctx_stack.top is not None
+def has_app_context():
+ """Worksl ike :func:`has_request_context` but for the application
+ context. You can also just do a boolean check on the
+ :data:`current_app` object instead.
+
+ .. versionadded:: 0.9
+ """
+ return _app_ctx_stack.top is not None
+
+
class AppContext(object):
"""The application context binds an application object implicitly
to the current thread or greenlet, similar to how the
Please sign in to comment.
Something went wrong with that request. Please try again.