diff --git a/CHANGES b/CHANGES index a6fa7ec6..3fb30c6f 100644 --- a/CHANGES +++ b/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 -------------- diff --git a/docs/config.rst b/docs/config.rst index 85051e4a..d0e1bcdb 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 2bff6af0..f10da8de 100644 --- a/flask/app.py +++ b/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, diff --git a/flask/testsuite/templating.py b/flask/testsuite/templating.py index 0f0ad5b4..8a6829dd 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'