Determine if Django is running under the development server

django, python

Solution

As suggested by Bernhard Vallant, you can just check for `runserver` in `sys.argv`.

You can just replace your `DEBUG` assignment in `settings.py` with this:

DEBUG = (sys.argv[1] == 'runserver')

You should also `import sys` somewhere in `settings.py`.

Problem

Is there a way to determine if Django is running on localhost and setting the `DEBUG` variable in `settings.py` accordingly. So that if I run the server locally it will set `DEBUG` to `True` and otherwise set it to `False`. Localhost: `python manage.py runserver` Not localhost: `python manage.py runserver 0.0.0.0:8000`

Original source

Related problems