How can I tell whether my Django application is running on development server or not?

后端 未结 13 1539
别跟我提以往
别跟我提以往 2020-12-05 03:37

How can I be certain that my application is running on development server or not? I suppose I could check value of settings.DEBUG and assume if DEBUG

13条回答
  •  無奈伤痛
    2020-12-05 04:31

    I put the following in my settings.py to distinguish between the standard dev server and production:

    import sys
    RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')
    

    This also relies on convention, however.

    (Amended per Daniel Magnusson's comment)

提交回复
热议问题