forked from orbit-oss/flask
Config is now available in templates, context processors no longer override keys
This commit is contained in:
parent
ed16ae2183
commit
aa3d8398fd
5 changed files with 47 additions and 1 deletions
11
flask/app.py
11
flask/app.py
|
|
@ -343,7 +343,11 @@ class Flask(_PackageBoundObject):
|
|||
|
||||
def update_template_context(self, context):
|
||||
"""Update the template context with some commonly used variables.
|
||||
This injects request, session and g into the template context.
|
||||
This injects request, session, config and g into the template
|
||||
context as well as everything template context processors want
|
||||
to inject. Note that the as of Flask 0.6, the original values
|
||||
in the context will not be overriden if a context processor
|
||||
decides to return a value with the same key.
|
||||
|
||||
:param context: the context as a dictionary that is updated in place
|
||||
to add extra variables.
|
||||
|
|
@ -352,8 +356,13 @@ class Flask(_PackageBoundObject):
|
|||
mod = _request_ctx_stack.top.request.module
|
||||
if mod is not None and mod in self.template_context_processors:
|
||||
funcs = chain(funcs, self.template_context_processors[mod])
|
||||
orig_ctx = context.copy()
|
||||
for func in funcs:
|
||||
context.update(func())
|
||||
# make sure the original values win. This makes it possible to
|
||||
# easier add new variables in context processors without breaking
|
||||
# existing views.
|
||||
context.update(orig_ctx)
|
||||
|
||||
def run(self, host='127.0.0.1', port=5000, **options):
|
||||
"""Runs the application on a local development server. If the
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ def _default_template_ctx_processor():
|
|||
"""
|
||||
reqctx = _request_ctx_stack.top
|
||||
return dict(
|
||||
config=reqctx.app.config,
|
||||
request=reqctx.request,
|
||||
session=reqctx.session,
|
||||
g=reqctx.g
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue