Determine if Django is running under the development server

后端 未结 3 2085
臣服心动
臣服心动 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 03:58

    As suggested by Bernhard Vallant, you can just check for runserver in sys.argv.

    You can just replace your DEBUG assignment in settings.py with this:

    DEBUG = (sys.argv[1] == 'runserver')
    

    You should also import sys somewhere in settings.py.

提交回复
热议问题