How can I tell whether my Django application is running on development server or not?

Viewed 27554

How can I be certain that my application is running on development server or not? I suppose I could check value of settings.DEBUG and assume if DEBUG is True then it's running on development server, but I'd prefer to know for sure than relying on convention.

13 Answers

You can determine whether you're running under WSGI (mod_wsgi, gunicorn, waitress, etc.) vs. manage.py (runserver, test, migrate, etc.) or anything else:

import sys
WSGI = 'django.core.wsgi' in sys.modules

You could check request.META["SERVER_SOFTWARE"] value:

dev_servers = ["WSGIServer", "Werkzeug"]
if any(server in request.META["SERVER_SOFTWARE"] for server in dev_servers):
    print("is local")
Related