周りを見回した後、私は次のコードを思いつきました。これはうまくいくようです.
設定/初期化.py
import sys
import socket
# try to import settings file based on machine name.
try:
settings = sys.modules[__name__]
host_settings_module_name = '%s' % (socket.gethostname().replace('.', '_'))
host_settings = __import__(host_settings_module_name, globals(), locals(), ['*'], -1)
# Merge imported settings over django settings
for key in host_settings.__dict__.keys():
if key.startswith('_'): continue #skip privates and __internals__
settings.__dict__[key] = host_settings.__dict__[key]
except Exception, e:
print e
from settings.site import *
設定/base.py
BASE = 1
SITE = 1
LOCAL = 1
settings/site.py //プロジェクト固有
from settings.base import *
SITE = 2
LOCAL = 2
settings/machine_name_local.py //開発者またはホスト サーバーのマシン固有の設定
from settings.site import *
LOCAL = 3