From 3e485009a8ca606c742c88c92cfd178547b708cd Mon Sep 17 00:00:00 2001 From: defuz Date: Mon, 30 Sep 2013 18:40:35 +0300 Subject: [PATCH] add TEMPLATES_AUTO_RELOAD option to config --- CHANGES | 4 ++++ docs/config.rst | 9 +++++++++ flask/app.py | 7 +++++++ flask/testsuite/templating.py | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/CHANGES b/CHANGES index 8699718c..acba98db 100644 --- a/CHANGES +++ b/CHANGES @@ -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 it’s possible to disable that. + Version 0.10.2 -------------- diff --git a/docs/config.rst b/docs/config.rst index 1bc46afa..55e34786 100644 --- a/docs/config.rst +++ b/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 ---------------------- diff --git a/flask/app.py b/flask/app.py index 1ea82fe7..066de664 100644 --- a/flask/app.py +++ b/flask/app.py @@ -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, diff --git a/flask/testsuite/templating.py b/flask/testsuite/templating.py index b2870dea..135612c1 100644 --- a/flask/testsuite/templating.py +++ b/flask/testsuite/templating.py @@ -295,6 +295,14 @@ class TemplatingTestCase(FlaskTestCase): rv = app.test_client().get('/') self.assert_equal(rv.data, b'

Jameson

') + 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()