add TEMPLATES_AUTO_RELOAD option to config

This commit is contained in:
defuz 2013-09-30 18:40:35 +03:00
parent 5d20501604
commit 3e485009a8
4 changed files with 28 additions and 0 deletions

View file

@ -15,6 +15,10 @@ Version 1.0
Non permanent sessions are not affected by this and will always
expire if the browser window closes.
- Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the
templates will be reloaded only if the application is running in
debug mode. For higher performance its possible to disable that.
Version 0.10.2
--------------

View file

@ -174,6 +174,12 @@ The following configuration values are used internally by Flask:
if they are not requested by an
XMLHttpRequest object (controlled by
the ``X-Requested-With`` header)
``TEMPLATES_AUTO_RELOAD`` Flask checks if template was modified each
time it is requested and reloads it if
necessary. But disk I/O is costly and it may
be viable to disable this feature by setting
this key to ``False``. This option does not
affect debug mode.
================================= =========================================
.. admonition:: More on ``SERVER_NAME``
@ -222,6 +228,9 @@ The following configuration values are used internally by Flask:
.. versionadded:: 1.0
``SESSION_REFRESH_EACH_REQUEST``
.. versionadded:: 1.0
``TEMPLATES_AUTO_RELOAD``
Configuring from Files
----------------------

View file

@ -294,6 +294,7 @@ class Flask(_PackageBoundObject):
'JSON_AS_ASCII': True,
'JSON_SORT_KEYS': True,
'JSONIFY_PRETTYPRINT_REGULAR': True,
'TEMPLATES_AUTO_RELOAD': True,
})
#: The rule object to use for URL rules created. This is used by
@ -644,10 +645,16 @@ class Flask(_PackageBoundObject):
this function to customize the behavior.
.. versionadded:: 0.5
.. versionchanged:: 1.0
``Environment.auto_reload`` set in accordance with
``TEMPLATES_AUTO_RELOAD`` configuration option.
"""
options = dict(self.jinja_options)
if 'autoescape' not in options:
options['autoescape'] = self.select_jinja_autoescape
if 'auto_reload' not in options:
options['auto_reload'] = self.debug \
or self.config['TEMPLATES_AUTO_RELOAD']
rv = Environment(self, **options)
rv.globals.update(
url_for=url_for,

View file

@ -295,6 +295,14 @@ class TemplatingTestCase(FlaskTestCase):
rv = app.test_client().get('/')
self.assert_equal(rv.data, b'<h1>Jameson</h1>')
def test_templates_auto_reload(self):
app = flask.Flask(__name__)
self.assert_true(app.config['TEMPLATES_AUTO_RELOAD'])
self.assert_true(app.jinja_env.auto_reload)
app = flask.Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = False
self.assert_false(app.jinja_env.auto_reload)
def suite():
suite = unittest.TestSuite()