If the configuration templates_auto_reload is set up after has set up it's jinja environment (example: after setting up some filters), it is ignored by Flask
Templates should be reloaded when app.config['TEMPLATES_AUTO_RELOAD'] is set to True
# application.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello(name=None):
return render_template('hello.html', name=name)
# Templates are reloaded if configuration is set up before the template filter
# app.config.update({'TEMPLATES_AUTO_RELOAD': True})
@app.template_filter('dummy')
def dummy(value):
return value
# Setting this up here does not do anything
app.config.update({'TEMPLATES_AUTO_RELOAD': True})
# Neither does this:
app.templates_auto_reload = True
app.run()
#% python application.py
The option is ignored because the jinja environment was already created
Is this really a problem?
Shouldn't config be set before any routes, template filters etc are defined?
Close it for now. It seems not a problem, I can't figure out a use case.
I've had this exact use case while developing my software (debug was OFF):
Took me the best part of an hour to figure out the problem
@romuald why not set TEMPLATES_AUTO_RELOAD=true before .run()?
Configuration should happen as early as possible. Nothing is guaranteed to read configuration after it initializes.
@ozzywalsh that's what I've done, moved the templates filter in a specific module specifically loaded after the configuration
Most helpful comment
Is this really a problem?
Shouldn't config be set before any routes, template filters etc are defined?