skip to Main Content

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


  1. 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.

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search