Django有两套配置文件,默认配置, 用户的配置
如果某个字段,用户配置了,就用用户的配置文件,如果没配置,就用默认的django配置文件
1.新建一个python项目
启动文件—test.py
import os os.environ.setdefault('user_setting', 'usersetting.setting') from conf import settings print(settings.DEBUG)
conf
——init.py
import os import importlib from conf import globalsetting class Setting: def __init__(self): user_setting = os.environ.get('user_setting') for setting in dir(globalsetting): if setting.isupper(): setattr(self, setting, getattr(globalsetting, setting)) mod = importlib.import_module(user_setting) for setting in dir(mod): if setting.isupper(): setattr(self, setting, getattr(mod, setting)) settings = Setting()