Skip to content

Commit

Permalink
Added proxies to template context
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Dec 21, 2012
1 parent 1949c4a commit 2af0ffa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Expand Up @@ -39,6 +39,10 @@ Release date to be decided.
- ``flask.Flask.request_globals_class`` got renamed to
``flask.Flask.app_ctx_globals_class`` which is a better name to what it
does since 0.10.
- `request`, `session` and `g` are now also added as proxies to the template
context which makes them available in imported templates. One has to be
very careful with those though because usage outside of macros might
cause caching.

Version 0.9
-----------
Expand Down
10 changes: 8 additions & 2 deletions flask/app.py
Expand Up @@ -29,7 +29,7 @@
from .wrappers import Request, Response
from .config import ConfigAttribute, Config
from .ctx import RequestContext, AppContext, _AppCtxGlobals
from .globals import _request_ctx_stack, request
from .globals import _request_ctx_stack, request, session, g
from .sessions import SecureCookieSessionInterface
from .module import blueprint_is_module
from .templating import DispatchingJinjaLoader, Environment, \
Expand Down Expand Up @@ -663,7 +663,13 @@ def create_jinja_environment(self):
rv.globals.update(
url_for=url_for,
get_flashed_messages=get_flashed_messages,
config=self.config
config=self.config,
# request, session and g are normally added with the
# context processor for efficiency reasons but for imported
# templates we also want the proxies in there.
request=request,
session=session,
g=g
)
rv.filters['tojson'] = json.htmlsafe_dumps
return rv
Expand Down

0 comments on commit 2af0ffa

Please sign in to comment.