New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable template auto-reloading in app.run() #1910
Enable template auto-reloading in app.run() #1910
Conversation
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).
This looks fine to me, although I'd prefer another maintainer sign off as well before it's merged. Can you add a test though? |
No problem, I'll add a test to this later this evening. Thanks. |
@@ -839,6 +839,8 @@ def run(self, host=None, port=None, debug=None, **options): | |||
options.setdefault('use_reloader', self.debug) | |||
options.setdefault('use_debugger', self.debug) | |||
options.setdefault('passthrough_errors', True) | |||
if debug: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
I don't think so - that's the root of the problem. The template reloader gets disabled at Flask app instantiation if it's not explicitly enabled and debug mode isn't turned on at that point. However, in the case if the code reloader, reloading is enabled in I think the patch harmonises the behaviour between template and code reloading (if no explicit reloading configuration and debug is enabled via |
I think you're confusing the template reloader of Jinja (enabled by default) with the server reloader from Werkzeug (disabled by default). |
And TEMPLATES_AUTO_RELOAD controls how Jinja's Line 695 in 5c12721
|
Sorry, I see that you've figured all of this already out in #1907 (comment). In that case I would say that we need to deduplicate that logic anyway, i.e. remove the logic for TEMPLATE_AUTO_RELOAD out of |
@untitaker That's the problem. If you don't explicitly enable debug via configuration at Flask app instantiation then access the I think the intention is that calling Sorry if I'm not explaining this very well.. |
Yes I oversaw your post in #1907, it all makes sense. But with this fix there's another inconsistency: If I explicitly set |
@davb5 What i meant specifically was using |
You are confusing Werkzeug server reloading with Jinja env reloading. On 14 June 2016 23:36:46 CEST, Alec Nikolas Reiter notifications@github.com wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
Ah, I understand now @untitaker. Sorry, I missed that comment. You're right in that we're clobbering any configuration set value from The difficulty here is that between instantiating our Flask app and calling My proposed patch works for most scenarios but fails for the one you've highlighted - if we explicitly disable template auto reloading (using any of the above mechanisms) then call @justanr's comment that we might want to use I think you're right in that moving the logic for TEMPLATE_AUTO_RELOAD into What does Jinja do if If so, we could probably just move that block from |
Actually, that might not work without some more changes. I don't believe |
Actually, #1910 (comment) might not matter as I don't think the Werkzeug auto reloader works in a WSGI environment (could someone please confirm?). If we don't auto reload code in a WSGI environment, keeping the template auto reloader configuration in However, it would appear that Jinja defaults to auto_reload=True. Moving the config code from I think we'll need a different approach (clobbering the value in |
I've added a test for the original patch (wether or not we use that solution, it's a starting point for the unit test). |
A quick workaround is to enable it manually:
I guess this issue is blocking a lot of people who use flask to develop templates. |
Thank goodness I found this, I've been tearing my hair out for a few hours trying to figure out why my templates weren't auto updating. I guess while running apt-get upgrade I didn't notice that I had updated to 0.11.1 which has this issue. What release are you guys targeting for this fix? |
Adding |
needs a rebase! |
closing due to inactivity. please consider re-opening this pull request :) |
Sorry for close/reopen spam, was trying to see if "allow edits from maintainers" was enabled for the PR. I'm going to continue this in another PR. |
So, I'm at a loss. I've tried every proposed solution I've been able to find, without luck. My locally run Flask app completely ignores any changes made to my html template files, no matter what I do. I've even redefined the location of the template folder via I've tried every permutation of setting debug and auto_reload I can think of. I currently have it running with a solution proposed in this thread (code below) - no errors, but still it completely ignores any changes made to template html files. Am I going mad? What could I be missing? EDIT: nevermind, realized I wasn't even calling the file I'd been editing. New to flask :) |
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).