Browse Source

set TEMPLATE_AUTO_RELOAD default value to None

pull/1222/head
defuz 10 years ago
parent
commit
f88765d504
  1. 6
      CHANGES
  2. 12
      docs/config.rst
  3. 8
      flask/app.py
  4. 30
      tests/test_templating.py

6
CHANGES

@ -23,9 +23,9 @@ Version 1.0
- Added :meth:`flask.Config.from_json`. - Added :meth:`flask.Config.from_json`.
- Added :attr:`flask.Flask.config_class`. - Added :attr:`flask.Flask.config_class`.
- Added :meth:`flask.config.Config.get_namespace`. - Added :meth:`flask.config.Config.get_namespace`.
- Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the - Added ``TEMPLATES_AUTO_RELOAD`` config key. Now by default templates will be
templates will be reloaded only if the application is running in reloaded every time a template is requested only if the application is
debug mode. For higher performance it’s possible to disable that. running in debug mode.
- Added a workaround for a limitation in Python 3.3's namespace loader. - Added a workaround for a limitation in Python 3.3's namespace loader.
- Added support for explicit root paths when using Python 3.3's namespace - Added support for explicit root paths when using Python 3.3's namespace
packages. packages.

12
docs/config.rst

@ -182,12 +182,12 @@ The following configuration values are used internally by Flask:
if they are not requested by an if they are not requested by an
XMLHttpRequest object (controlled by XMLHttpRequest object (controlled by
the ``X-Requested-With`` header) the ``X-Requested-With`` header)
``TEMPLATES_AUTO_RELOAD`` Flask checks if template was modified each ``TEMPLATES_AUTO_RELOAD`` If this is set to `True` every time a template
time it is requested and reloads it if is requested Flask checks if the template was
necessary. But disk I/O is costly and it may modified and if yes, it will reload the
be viable to disable this feature by setting template. By default the value is ``None``
this key to ``False``. This option does not which means that Flask checks template
affect debug mode. sources only in debug mode.
``EXPLAIN_TEMPLATE_LOADING`` If this is enabled then every attempt to ``EXPLAIN_TEMPLATE_LOADING`` If this is enabled then every attempt to
load a template will write an info load a template will write an info
message to the logger explaining the message to the logger explaining the

8
flask/app.py

@ -297,7 +297,7 @@ class Flask(_PackageBoundObject):
'JSON_AS_ASCII': True, 'JSON_AS_ASCII': True,
'JSON_SORT_KEYS': True, 'JSON_SORT_KEYS': True,
'JSONIFY_PRETTYPRINT_REGULAR': True, 'JSONIFY_PRETTYPRINT_REGULAR': True,
'TEMPLATES_AUTO_RELOAD': True, 'TEMPLATES_AUTO_RELOAD': None,
}) })
#: The rule object to use for URL rules created. This is used by #: The rule object to use for URL rules created. This is used by
@ -673,8 +673,10 @@ class Flask(_PackageBoundObject):
if 'autoescape' not in options: if 'autoescape' not in options:
options['autoescape'] = self.select_jinja_autoescape options['autoescape'] = self.select_jinja_autoescape
if 'auto_reload' not in options: if 'auto_reload' not in options:
options['auto_reload'] = self.debug \ if self.config['TEMPLATES_AUTO_RELOAD'] is not None:
or self.config['TEMPLATES_AUTO_RELOAD'] options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']
else:
options['auto_reload'] = self.debug
rv = Environment(self, **options) rv = Environment(self, **options)
rv.globals.update( rv.globals.update(
url_for=url_for, url_for=url_for,

30
tests/test_templating.py

@ -296,12 +296,36 @@ def test_iterable_loader():
assert rv.data == b'<h1>Jameson</h1>' assert rv.data == b'<h1>Jameson</h1>'
def test_templates_auto_reload(): def test_templates_auto_reload():
# debug is False, config option is None
app = flask.Flask(__name__) app = flask.Flask(__name__)
assert app.config['TEMPLATES_AUTO_RELOAD'] assert app.debug is False
assert app.jinja_env.auto_reload assert app.config['TEMPLATES_AUTO_RELOAD'] is None
assert app.jinja_env.auto_reload is False
# debug is False, config option is False
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = False app.config['TEMPLATES_AUTO_RELOAD'] = False
assert not app.jinja_env.auto_reload assert app.debug is False
assert app.jinja_env.auto_reload is False
# debug is False, config option is True
app = flask.Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
assert app.debug is False
assert app.jinja_env.auto_reload is True
# debug is True, config option is None
app = flask.Flask(__name__)
app.config['DEBUG'] = True
assert app.config['TEMPLATES_AUTO_RELOAD'] is None
assert app.jinja_env.auto_reload is True
# debug is True, config option is False
app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['TEMPLATES_AUTO_RELOAD'] = False
assert app.jinja_env.auto_reload is False
# debug is True, config option is True
app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
assert app.jinja_env.auto_reload is True
def test_template_loader_debugging(test_apps): def test_template_loader_debugging(test_apps):
from blueprintapp import app from blueprintapp import app

Loading…
Cancel
Save