Determine if Django is running under the development server

后端 未结 3 2073
臣服心动
臣服心动 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:08

    This is not the best approach, but it works :)
    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
        #...
    

提交回复
热议问题