From 2af0ffaef63dbd6031d889d28e4d60794becb7b6 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 21 Dec 2012 11:47:27 +0100 Subject: [PATCH] Added proxies to template context --- CHANGES | 4 ++++ flask/app.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index ddba0928..044dae44 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ----------- diff --git a/flask/app.py b/flask/app.py index 902c2ba8..162a1d44 100644 --- a/flask/app.py +++ b/flask/app.py @@ -29,7 +29,7 @@ from . import json 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, \ @@ -663,7 +663,13 @@ class Flask(_PackageBoundObject): 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