I wrote a Django 2.2 program that works well in my PC running Windows 10 and my VPS, running CentOS 7.
When I changed some code in three files, the application continues to work locally but behaves strangely in prouduction.
When I run
python manage.py runserver 0.0.0.0:80
on my server, I get this following response:
***a.py changed, reloading.
Watching for file changes with StatReloader
***b.py changed, reloading.
Watching for file changes with StatReloader
***c.py changed, reloading.
Watching for file changes with StatReloader
***a.py changed, reloading.
Watching for file changes with StatReloader
***b.py changed, reloading.
Watching for file changes with StatReloader
I modified these files before deploying, but they shouldn’t be changing while the site is running.
Adding the --noreload
flag prevents this:
python manage.py runserver --noreload 0.0.0.0:80
Why is this required?
2
Answers
manage.py runserver
is only meant for development:Add a WSGI server like Gunicorn, Waitress, or uWSGI to your dependencies and run that, e.g.:
Typically, to deploy Gunicorn in production you wouldn’t bind directly to port 80 but instead use something like Nginx.
When you run Django program in production, Please change the option of DEBUG = True to DEBUG = False in settings.py.