Skip to content
Myr

Allow custom jinja environments

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This is useful e.g. when using the new Jinja Environment attributes added in mitsuhiko/jinja2#404

authored by ThiefMaster · committed by ThiefMaster · parent dac45f6 · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−1 removed

  • tests:+10 added−0 removed
  • other:+6 added−1 removed

2 files+16 added−1 removed

modified:flask/app.py+6 added-1 removed
155 unmodified lines
156 #: The class that is used for response objects. See157 #: :class:`~flask.Response` for more information.158 response_class = Response159160 #: The class that is used for the Jinja environment.161 #:162 #: .. versionadded:: 0.11163 jinja_env_class = Environment164165 #: The class that is used for the :data:`~flask.g` instance.166 #:167 #: Example use cases for a custom class:168 #:
515 unmodified lines
684 if self.config['TEMPLATES_AUTO_RELOAD'] is not None:685 options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']686 else:687 options['auto_reload'] = self.debug683 rv = Environment(self, **options)688 rv = self.jinja_env_class(self, **options)689 rv.globals.update(690 url_for=url_for,691 get_flashed_messages=get_flashed_messages,692 config=self.config,
1239 unmodified lines
modified:tests/test_templating.py+10 added
359 unmodified lines
360 app.logger.handlers[:] = old_handlers361 app.config['EXPLAIN_TEMPLATE_LOADING'] = old_load_setting362363 assert len(called) == 1364365def test_custom_jinja_env():366 class CustomEnvironment(flask.templating.Environment):367 pass368369 class CustomFlask(flask.Flask):370 jinja_env_class = CustomEnvironment371372 app = CustomFlask(__name__)373 assert isinstance(app.jinja_env, CustomEnvironment)