Say you have
in debug_settings.py
DEBUG = True
from base_settings import *
in product_settings.py
DEBUG = False
from base_settings import *
in base_settings.py
# this condition check is problamatic, I don't think I can define DEBUG variable outside of `base_settings.py` ?
if DEBUG:
foo()
How do you have a common base_settings.py which has conditional code dependant on variable (DEBUG) whose value can be changed from the importing module? (from debug_settings, product_settings)
A better way to do this would be to use environment variables
in debug_settings.py:
os.environ["DEBUG"] = "TRUE"
in product_settings.py:
os.environ["DEBUG"] = "FALSE"
then in base_settings.py:
if os.getenv("DEBUG", "TRUE"): #The second argument specifies the default in case "DEBUG" has not been set
foo()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.