0

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?

Chris
  • 112,704
  • 77
  • 249
  • 231
betterpan
  • 11
  • 1

2 Answers2

2

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.

Chris
  • 112,704
  • 77
  • 249
  • 231
  • Thank you! It can't work in uwsgi,so I test it in the command line – betterpan Apr 11 '20 at 13:58
  • @betterpan, I don't understand. Did this work or not? – Chris Apr 11 '20 at 14:00
  • Thank you! It work in windows10 ,but can't work in centos7 shell . – betterpan Apr 11 '20 at 14:13
  • It reloading forever,with out "--noreload" – betterpan Apr 11 '20 at 14:24
  • ...but you shouldn't be using `manage.py runserver` on the server at all. Did you try what I suggested in my answer? – Chris Apr 11 '20 at 14:24
  • I used UWSGI before I edit the program,but uwsgi show error info after I edit the program code...I write a question like [https://stackoverflow.com/questions/60485511],but can't post now... – betterpan Apr 11 '20 at 14:29
  • That's no excuse to use `manage.py runserver` in production. Ask about your _actual problem_, not whatever you think the solution is. Please read about the [XY problem](https://meta.stackexchange.com/q/66377/248627). – Chris Apr 11 '20 at 14:31
  • I think a correct program code should be run in 'manage.py runserver',even in vps...I did't use it for a long time...Thank you – betterpan Apr 11 '20 at 14:35
  • 1
    @betterpan, no, `manage.py runserver` should _not_ be used in production. It's weird that you're getting the reloading, but it's also _irrelevant_. _Do **not** use `manage.py runserver` on your server_. – Chris Apr 11 '20 at 14:36
  • Thank you very much! Can you help me about this question ? https://stackoverflow.com/questions/61158883 – betterpan Apr 11 '20 at 15:04
0

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

douyu
  • 2,153
  • 1
  • 12
  • 23