I need a way to distinguish development server in Django (run eg. by ./manage.py runserver 0.0.0.0:8000
) from the one being run on Apache. In case of Apache I use WSGI daemon mode, but I would like to find some more reliable solution for detecting execution on Django's development server.
What I currently use is similar to:
wsgi_wrapper = request.META.get('wsgi.file_wrapper')
wsgi_wrapper_path = wsgi_wrapper.__module__ if wsgi_wrapper else None
which seemingly gives wsgi_wrapper_path
storing:
- "
wsgiref.util
" string when run on Django's built-in development server, None
when run on Apache / WSGI in daemon mode,
The problem here is I am not sure if I can rely on that check (eg. if the production/staging/development server or my localhost configuration changes). I was not able to find any documentation regarding that.
I need that check primarily because of one issue with Django's development server: it sets request's CONTENT_TYPE
(request.META['CONTENT_TYPE']
) to "text/plain
" even if the HTTP request itself had no content type set (eg. it was a GET
request).
Any ideas regarding Django's development server detection (or solving issue with incorrect request content type on it) will be appreciated. Thanks.
Ps. I am basically asking this question: How can I tell whether my Django application is running on development server or not? for Django 1.4, trying to determine the solution that will be reliable enough in case configuration changes.