From 0514ba2de1751de1b0c9a223c96f6a7145714e6a Mon Sep 17 00:00:00 2001 From: Dave Barker Date: Tue, 14 Jun 2016 00:59:32 +0100 Subject: [PATCH] Enable template auto-reloading in app.run() When Flask app debugging is enabled (app.debug==True), and Jinja2 template auto-reloading is not explicitly disbaled, template auto-reloading should be enabled. If the app is instantiated, the jinja_env object is accessed (thereby initialising the Jinja2 environment) and the server is then started with app.run(debug=True), template auto-reloading is *not* enabled. This is because reading the jinja_env object causes the environment initialisation function to set auto_reload to app.debug (which isn't yet True). Calling app.run(debug=True) should correct this in order to remain consistent with Flask code reloading (which is enabled within app.run() if debug == True). --- flask/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flask/app.py b/flask/app.py index b1ea0464..1d32ece9 100644 --- a/flask/app.py +++ b/flask/app.py @@ -839,6 +839,8 @@ class Flask(_PackageBoundObject): options.setdefault('use_reloader', self.debug) options.setdefault('use_debugger', self.debug) options.setdefault('passthrough_errors', True) + if debug: + self.jinja_env.auto_reload = True try: run_simple(host, port, self, **options) finally: