Merge branch 'ThiefMaster-override-jinja-env'
This commit is contained in:
commit
d00f5cc9fe
4 changed files with 18 additions and 3 deletions
|
|
@ -157,6 +157,11 @@ class Flask(_PackageBoundObject):
|
||||||
#: :class:`~flask.Response` for more information.
|
#: :class:`~flask.Response` for more information.
|
||||||
response_class = Response
|
response_class = Response
|
||||||
|
|
||||||
|
#: The class that is used for the Jinja environment.
|
||||||
|
#:
|
||||||
|
#: .. versionadded:: 1.0
|
||||||
|
jinja_env_class = Environment
|
||||||
|
|
||||||
#: The class that is used for the :data:`~flask.g` instance.
|
#: The class that is used for the :data:`~flask.g` instance.
|
||||||
#:
|
#:
|
||||||
#: Example use cases for a custom class:
|
#: Example use cases for a custom class:
|
||||||
|
|
@ -680,7 +685,7 @@ class Flask(_PackageBoundObject):
|
||||||
options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']
|
options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']
|
||||||
else:
|
else:
|
||||||
options['auto_reload'] = self.debug
|
options['auto_reload'] = self.debug
|
||||||
rv = Environment(self, **options)
|
rv = self.jinja_env_class(self, **options)
|
||||||
rv.globals.update(
|
rv.globals.update(
|
||||||
url_for=url_for,
|
url_for=url_for,
|
||||||
get_flashed_messages=get_flashed_messages,
|
get_flashed_messages=get_flashed_messages,
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,7 @@ class Blueprint(_PackageBoundObject):
|
||||||
application-wide function of the :class:`~flask.Flask` object but
|
application-wide function of the :class:`~flask.Flask` object but
|
||||||
for error handlers limited to this blueprint.
|
for error handlers limited to this blueprint.
|
||||||
|
|
||||||
.. versionadded:: 0.11
|
.. versionadded:: 1.0
|
||||||
"""
|
"""
|
||||||
self.record_once(lambda s: s.app._register_error_handler(
|
self.record_once(lambda s: s.app._register_error_handler(
|
||||||
self.name, code_or_exception, f))
|
self.name, code_or_exception, f))
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class Request(RequestBase):
|
||||||
is considered to include JSON data if the mimetype is
|
is considered to include JSON data if the mimetype is
|
||||||
:mimetype:`application/json` or :mimetype:`application/*+json`.
|
:mimetype:`application/json` or :mimetype:`application/*+json`.
|
||||||
|
|
||||||
.. versionadded:: 0.11
|
.. versionadded:: 1.0
|
||||||
"""
|
"""
|
||||||
mt = self.mimetype
|
mt = self.mimetype
|
||||||
if mt == 'application/json':
|
if mt == 'application/json':
|
||||||
|
|
|
||||||
|
|
@ -361,3 +361,13 @@ def test_template_loader_debugging(test_apps):
|
||||||
app.config['EXPLAIN_TEMPLATE_LOADING'] = old_load_setting
|
app.config['EXPLAIN_TEMPLATE_LOADING'] = old_load_setting
|
||||||
|
|
||||||
assert len(called) == 1
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue