Auto reloading python Flask app upon code changes
I'm investigating how to develop a decent web app with Python. Since I don't want some high-order structures to get in my way, my choice fell on the lightweight Flask framework. Time will tell if this was the right choice.
So, now I've set up an Apache server with mod_wsgi, and my test site is running fine. However, I'd like to speed up the development routine by making the site automatically reload upon any changes in py or template files I make. I see that any changes in site's .wsgi file causes reloading (even without WSGIScriptReloading On in the apache config file), but I still have to prod it manually (ie, insert extra linebreak, save). Is there some way how to cause reload when I edit some of the app's py files? Or, I am expected to use IDE that refreshes the .wsgi file for me?
The current recommended way (Flask >= 0.11) is with the
flask command line utility.
$ export FLASK_APP=main.py $ export FLASK_DEBUG=1 $ python -m flask run
or in one command:
$ FLASK_APP=main.py FLASK_DEBUG=1 python -m flask run
python -m flask run rather than
flask run because the former also works with
If you want different port than the default (
$ python -m flask run --port 8080
More options are available with:
$ python -m flask run --help
★ Back to homepage or read more recommendations: