[ACCEPTED]-Determine if Django is running under the development server-django
As suggested by Bernhard Vallant, you can 3 just check for runserver
in sys.argv
.
You can just replace 2 your DEBUG
assignment in settings.py
with this:
DEBUG = (sys.argv[1] == 'runserver')
You should 1 also import sys
somewhere in settings.py
.
This is not the best approach, but it works 1 :)
For something better you can use django-configurations
import sys
# Determine if in Production or Development
if (len(sys.argv) >= 2 and sys.argv[1] == 'runserver'):
DEBUG = True
#...
else:
DEBUG = False
#...
Could not have a permalink to this accepted 3 and related answer to your question. So, just 2 pasting it:-
server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print 'inside dev'
Of course, wsgi.file_wrapper might be set on META, and have a class from a module named django.core.servers.basehttp by extreme coincidence on another server environment, but I hope this will have you covered.
PS: Please refer to How can I tell whether my Django application is running on development server or not? for more 1 details
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.