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

Imran picture Imran · Aug 18, 2009 · Viewed 22.6k times · Source

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.

Answer

Aryeh Leib Taurog picture Aryeh Leib Taurog · Nov 25, 2010

I put the following in my settings.py to distinguish between the standard dev server and production:

import sys
RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')

This also relies on convention, however.

(Amended per Daniel Magnusson's comment)