1

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?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
betterpan
  • 21
  • 3

2 Answers2

3

manage.py runserver is only meant for development:

DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)

Add a WSGI server like Gunicorn, Waitress, or uWSGI to your dependencies and run that, e.g.:

gunicorn myproject.wsgi

Typically, to deploy Gunicorn in production you wouldn't bind directly to port 80 but instead use something like Nginx.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
0

When you run Django program in production, Please change the option of DEBUG = True to DEBUG = False in settings.py.

douyu
  • 2,377
  • 2
  • 14
  • 27