Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom jinja environments #1422

Merged
merged 1 commit into from
Jun 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class Flask(_PackageBoundObject):
#: :class:`~flask.Response` for more information.
response_class = Response

#: The class that is used for the Jinja environment.
#:
#: .. versionadded:: 0.11

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

jinja_env_class = Environment

#: The class that is used for the :data:`~flask.g` instance.
#:
#: Example use cases for a custom class:
Expand Down Expand Up @@ -680,7 +685,7 @@ def create_jinja_environment(self):
options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']
else:
options['auto_reload'] = self.debug
rv = Environment(self, **options)
rv = self.jinja_env_class(self, **options)
rv.globals.update(
url_for=url_for,
get_flashed_messages=get_flashed_messages,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,13 @@ def handle(x, record):
app.config['EXPLAIN_TEMPLATE_LOADING'] = old_load_setting

assert len(called) == 1

def test_custom_jinja_env():
class CustomEnvironment(flask.templating.Environment):
pass

class CustomFlask(flask.Flask):
jinja_env_class = CustomEnvironment

app = CustomFlask(__name__)
assert isinstance(app.jinja_env, CustomEnvironment)