Browse Source

Merge pull request #876 from defuz/templates-auto-reload

Add TEMPLATES_AUTO_RELOAD config key
pull/842/merge
Kenneth Reitz 11 years ago
parent
commit
7f5b6c692d
  1. 4
      CHANGES
  2. 9
      docs/config.rst
  3. 7
      flask/app.py
  4. 8
      flask/testsuite/templating.py

4
CHANGES

@ -21,6 +21,10 @@ Version 1.0
- Added :attr:`flask.Flask.config_class`.
- Added :meth:`flask.config.Config.get_namespace`.
- 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 it’s possible to disable that.
Version 0.10.2
--------------

9
docs/config.rst

@ -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
----------------------

7
flask/app.py

@ -305,6 +305,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
@ -655,10 +656,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,

8
flask/testsuite/templating.py

@ -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()

Loading…
Cancel
Save