Merge pull request #1222 from defuz/templates_auto_reload-eq-none
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Set TEMPLATE_AUTO_RELOAD default value to None
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 84efebd, 6a6acfb · Browse files · 4 files·+39 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+39 added−15 removed
- tests:+27 added−3 removed
- other:+12 added−12 removed
Provenance
- Commit
a1b2736- Tree
8300568- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
84efebd- Parent 2
6a6acfb
4 files changed+39 added−15 removed
modified:docs/config.rst+5 added-6 removed
180 unmodified lines181 jsonify responses will be pretty printed182 if they are not requested by an183 XMLHttpRequest object (controlled by184 the ``X-Requested-With`` header)185-``TEMPLATES_AUTO_RELOAD`` Flask checks if template was modified each186- time it is requested and reloads it if187- necessary. But disk I/O is costly and it may188- be viable to disable this feature by setting189- this key to ``False``. This option does not190- affect debug mode.185+``TEMPLATES_AUTO_RELOAD`` Whether to check for modifications of186+ the template source and reload it187+ automatically. By default the value is188+ ``None`` which means that Flask checks189+ original file only in debug mode.190 ``EXPLAIN_TEMPLATE_LOADING`` If this is enabled then every attempt to191 load a template will write an info192 message to the logger explaining the193 attempts to locate the template. This269 unmodified linesmodified:flask/app.py+5 added-3 removed
295 unmodified lines296 'PREFERRED_URL_SCHEME': 'http',297 'JSON_AS_ASCII': True,298 'JSON_SORT_KEYS': True,299 'JSONIFY_PRETTYPRINT_REGULAR': True,300- 'TEMPLATES_AUTO_RELOAD': True,300+ 'TEMPLATES_AUTO_RELOAD': None,301 })302 303 #: The rule object to use for URL rules created. This is used by304 #: :meth:`add_url_rule`. Defaults to :class:`werkzeug.routing.Rule`.367 unmodified lines672 options = dict(self.jinja_options)673 if 'autoescape' not in options:674 options['autoescape'] = self.select_jinja_autoescape675 if 'auto_reload' not in options:676- options['auto_reload'] = self.debug \677- or self.config['TEMPLATES_AUTO_RELOAD']676+ if self.config['TEMPLATES_AUTO_RELOAD'] is not None:677+ options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']678+ else:679+ options['auto_reload'] = self.debug680 rv = Environment(self, **options)681 rv.globals.update(682 url_for=url_for,683 get_flashed_messages=get_flashed_messages,1226 unmodified linesmodified:tests/test_templating.py+27 added-3 removed
294 unmodified lines295 rv = app.test_client().get('/')296 assert rv.data == b'<h1>Jameson</h1>'297 298 def test_templates_auto_reload():299+ # debug is False, config option is None300 app = flask.Flask(__name__)301+ assert app.debug is False300- assert app.config['TEMPLATES_AUTO_RELOAD']301- assert app.jinja_env.auto_reload302+ assert app.config['TEMPLATES_AUTO_RELOAD'] is None303+ assert app.jinja_env.auto_reload is False304+ # debug is False, config option is False305 app = flask.Flask(__name__)306 app.config['TEMPLATES_AUTO_RELOAD'] = False304- assert not app.jinja_env.auto_reload307+ assert app.debug is False308+ assert app.jinja_env.auto_reload is False309+ # debug is False, config option is True310+ app = flask.Flask(__name__)311+ app.config['TEMPLATES_AUTO_RELOAD'] = True312+ assert app.debug is False313+ assert app.jinja_env.auto_reload is True314+ # debug is True, config option is None315+ app = flask.Flask(__name__)316+ app.config['DEBUG'] = True317+ assert app.config['TEMPLATES_AUTO_RELOAD'] is None318+ assert app.jinja_env.auto_reload is True319+ # debug is True, config option is False320+ app = flask.Flask(__name__)321+ app.config['DEBUG'] = True322+ app.config['TEMPLATES_AUTO_RELOAD'] = False323+ assert app.jinja_env.auto_reload is False324+ # debug is True, config option is True325+ app = flask.Flask(__name__)326+ app.config['DEBUG'] = True327+ app.config['TEMPLATES_AUTO_RELOAD'] = True328+ assert app.jinja_env.auto_reload is True329 330 def test_template_loader_debugging(test_apps):331 from blueprintapp import app332 31 unmodified linesmodified:CHANGES+2 added-3 removed
21 unmodified lines22 from a view function.23 - Added :meth:`flask.Config.from_json`.24 - Added :attr:`flask.Flask.config_class`.25 - Added :meth:`flask.config.Config.get_namespace`.26-- Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the27- templates will be reloaded only if the application is running in28- debug mode. For higher performance it’s possible to disable that.26+- Templates are no longer automatically reloaded outside of debug mode. This27+ can be configured with the new ``TEMPLATES_AUTO_RELOAD`` config key.28 - Added a workaround for a limitation in Python 3.3's namespace loader.29 - Added support for explicit root paths when using Python 3.3's namespace30 packages.31 - Added ``flask`` and the ``flask.cli`` module to start the local507 unmodified lines