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

后端 未结 13 1607
别跟我提以往
别跟我提以往 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:19

    Typically I set a variable called environment and set it to "DEVELOPMENT", "STAGING" or "PRODUCTION". Within the settings file I can then add basic logic to change which settings are being used, based on environment.

    EDIT: Additionally, you can simply use this logic to include different settings.py files that override the base settings. For example:

    if environment == "DEBUG":
        from debugsettings import *
    

提交回复
热议问题