Determine if Django is running under the development server

后端 未结 3 2070
臣服心动
臣服心动 2021-02-20 03:09

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 s

3条回答
  •  孤城傲影
    2021-02-20 04:02

    Could not have a permalink to this accepted and related answer to your question. So, just 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 details

提交回复
热议问题