Method: flask.app.Flask.create_jinja_environment
Calls: 113, Exceptions: 0, Paths: 2Back
Path 1: 109 calls (0.96)
Environment (108) test_custom_jinja_env.
1def create_jinja_environment(self) -> Environment:
2 """Create the Jinja environment based on :attr:`jinja_options`
3 and the various Jinja-related methods of the app. Changing
4 :attr:`jinja_options` after this will have no effect. Also adds
5 Flask-related globals and filters to the environment.
6
7 .. versionchanged:: 0.11
8 ``Environment.auto_reload`` set in accordance with
9 ``TEMPLATES_AUTO_RELOAD`` configuration option.
10
11 .. versionadded:: 0.5
12 """
13 options = dict(self.jinja_options)
14
15 if "autoescape" not in options:
16 options["autoescape"] = self.select_jinja_autoescape
17
18 if "auto_reload" not in options:
19 auto_reload = self.config["TEMPLATES_AUTO_RELOAD"]
20
21 if auto_reload is None:
22 auto_reload = self.debug
23
24 options["auto_reload"] = auto_reload
25
26 rv = self.jinja_environment(self, **options)
27 rv.globals.update(
28 url_for=self.url_for,
29 get_flashed_messages=get_flashed_messages,
30 config=self.config,
31 # request, session and g are normally added with the
32 # context processor for efficiency reasons but for imported
33 # templates we also want the proxies in there.
34 request=request,
35 session=session,
36 g=g,
37 )
38 rv.policies["json.dumps_function"] = self.json.dumps
39 return rv
Path 2: 4 calls (0.04)
Environment (4)
1def create_jinja_environment(self) -> Environment:
2 """Create the Jinja environment based on :attr:`jinja_options`
3 and the various Jinja-related methods of the app. Changing
4 :attr:`jinja_options` after this will have no effect. Also adds
5 Flask-related globals and filters to the environment.
6
7 .. versionchanged:: 0.11
8 ``Environment.auto_reload`` set in accordance with
9 ``TEMPLATES_AUTO_RELOAD`` configuration option.
10
11 .. versionadded:: 0.5
12 """
13 options = dict(self.jinja_options)
14
15 if "autoescape" not in options:
16 options["autoescape"] = self.select_jinja_autoescape
17
18 if "auto_reload" not in options:
19 auto_reload = self.config["TEMPLATES_AUTO_RELOAD"]
20
21 if auto_reload is None:
22 auto_reload = self.debug
23
24 options["auto_reload"] = auto_reload
25
26 rv = self.jinja_environment(self, **options)
27 rv.globals.update(
28 url_for=self.url_for,
29 get_flashed_messages=get_flashed_messages,
30 config=self.config,
31 # request, session and g are normally added with the
32 # context processor for efficiency reasons but for imported
33 # templates we also want the proxies in there.
34 request=request,
35 session=session,
36 g=g,
37 )
38 rv.policies["json.dumps_function"] = self.json.dumps
39 return rv