我使用一种方法,其中我的设置实际上是一个包而不是模块
settings/
init .py base.py local.py #这个在.gitignore
初始化.py:
from setings import *
try:
from local.py import *
except ImportError:
pass
基础.py:
import os
DEBUG = False
TEMPLATE_DEBUG = DEBUG
SITE_ROOT = os.path.join( os.path.dirname( os.path.realpath(__file__) ) ,'..' )
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
etc...
本地.py:
from settings import settings as PROJECT_DEFAULT
PREPEND_WWW = False
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_pyscopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'somesecretname', # Or path to database file if using sqlite3.
'USER': 'somesecretuser', # Not used with sqlite3.
'PASSWORD': 'somesecretpassword', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
INSTALLED_APPS += PROJECT_DEFAULT.INSTALLED_APPS + ('debug_toolbar',)
你可以在这里看到一个例子