By default, when running Flask application using the built-in server (Flask.run
), it monitors its Python files and automatically reloads the app if its code cha
For me works just fine:
from flask import Flask, render_template, request, url_for, redirect
app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
See more on http://flask.pocoo.org/docs/1.0/config/
See http://flask.pocoo.org/docs/1.0/quickstart/
and use FLASK_ENV=development
Actually for me TEMPLATES_AUTO_RELOAD = True
does not work (0.12 version). I use jinja2 and what i have done:
Create function before_request
def before_request():
app.jinja_env.cache = {}
Register it in application
app.before_request(before_request)
That's it.
What worked for me is just adding this:
@app.before_request
def before_request():
# When you import jinja2 macros, they get cached which is annoying for local
# development, so wipe the cache every request.
if 'localhost' in request.host_url or '0.0.0.0' in request.host_url:
app.jinja_env.cache = {}
(taken from @dikkini's answer)