Method: flask.app.Flask.update_template_context
Calls: 42, Exceptions: 0, Paths: 2Back
Path 1: 38 calls (0.9)
{} (9) {'value': 'abcd'} (9) {'value': False} (9) dict (3) {'whiskey': 42} (2) {'value': 23} (2) {'config': 42} (2) {'foo': '
1def update_template_context(self, context: dict) -> None:
2 """Update the template context with some commonly used variables.
3 This injects request, session, config and g into the template
4 context as well as everything template context processors want
5 to inject. Note that the as of Flask 0.6, the original values
6 in the context will not be overridden if a context processor
7 decides to return a value with the same key.
8
9 :param context: the context as a dictionary that is updated in place
10 to add extra variables.
11 """
12 names: t.Iterable[str | None] = (None,)
13
14 # A template may be rendered outside a request context.
15 if request:
16 names = chain(names, reversed(request.blueprints))
17
18 # The values passed to render_template take precedence. Keep a
19 # copy to re-apply after all context functions.
20 orig_ctx = context.copy()
21
22 for name in names:
23 if name in self.template_context_processors:
24 for func in self.template_context_processors[name]:
25 context.update(func())
26
27 context.update(orig_ctx)
Path 2: 4 calls (0.1)
{} (4)
1def update_template_context(self, context: dict) -> None:
2 """Update the template context with some commonly used variables.
3 This injects request, session, config and g into the template
4 context as well as everything template context processors want
5 to inject. Note that the as of Flask 0.6, the original values
6 in the context will not be overridden if a context processor
7 decides to return a value with the same key.
8
9 :param context: the context as a dictionary that is updated in place
10 to add extra variables.
11 """
12 names: t.Iterable[str | None] = (None,)
13
14 # A template may be rendered outside a request context.
15 if request:
16 names = chain(names, reversed(request.blueprints))
17
18 # The values passed to render_template take precedence. Keep a
19 # copy to re-apply after all context functions.
20 orig_ctx = context.copy()
21
22 for name in names:
23 if name in self.template_context_processors:
24 for func in self.template_context_processors[name]:
25 context.update(func())
26
27 context.update(orig_ctx)