Does anyone know how to make a mod_wsgi
automatically reload a Flask app when any of the modules changes? I've tried WSGIScriptReloading On
, but no luck. The official documentation is kind of a bear ... I guess I'll give it a stab if no one knows. Thanks in advance!
Also, if it could not permanently crash on syntax errors (like the the Flask reloader), that'd be awesome.
Use the --debug option when you run your Flask app to enable debug mode. This will enable auto-reload whenever changes are made to your code and saved. It will also enable an interactive debugger in the browser if any errors occur during a request.
mod_wsgi is an Apache module which can host any Python WSGI application, including Django. Django will work with any version of Apache which supports mod_wsgi. The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi.
WSGI (Web Server Gateway Interface) is an interface between web servers and web apps for python. mod_wsgi is an Apache HTTP server module that enables Apache to serve Flask applications. We need to use the following command to install mod_wsgi: $ sudo apt-get install libapache2-mod-wsgi python-dev.
This "reloads" the code whenever you make a change so that you don't have to manually restart the app to see changes. It is quite useful when you're making frequent changes. You can turn off reloading by setting the debug parameter to False.
With mod_wsgi
, WSGIScriptReloading
looks for changes to the .wsgi
config file, rather than the code.
My workflow is to upload my code changes then just
$ touch MyWebApp.wsgi
which causes the last modified file timestamp to change and mod_wsgi
to reload the code.
You can do this 'remotely' by saving the .wsgi
file on your local machine and then uploading it again, or I just do it via SSH.
Not a lot you can do about syntax errors, the code is either running or it isn't, but a fix plus a touch
will get it running again.
One gotcha to look out for if you're working via FTP: make sure you upload the 'touched' .wsgi
file last otherwise it'll try and start with the wrong code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With