给定以下应用程序设置:
/Project/
/app1/
/app2/
/project/ (the project app that gets auto created in Django 1.4+)
/settings/
__init__.py <- general site inspecific settings
sitea.py <- site A's specific settings
siteb.py <- site B's specific settings
里面sitea.py
放站点特定的设置(您仍然可以使用os.environ.get()
调用来使用 heroku 存储的设置)。
# Default Django settings for project.
from project.settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
ALLOWED_HOSTS = []
MEDIA_ROOT = ''
STATIC_ROOT = ''
然后在你的heroku运行/启动脚本中做相当于(我假设你将使用gunicorn或其他一些生产django服务器)
python manage.py runserver --settings=project.settings.sitea
更新 - 一个示例Project/project/settings/production.py
文件,注意:所有敏感信息都是从环境中读取的,而不是从文件中读取的。
from project.settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Francis', 'francis@teamcolab.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.environ.get('MYSQL_DATABASE'), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': os.environ.get('MYSQL_USER'),
'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
'HOST': os.environ.get('MYSQL_HOST'), # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': os.environ.get('MYSQL_PORT'), # Set to empty string for default.
}
}
REDIS = {
'HOST' : os.environ.get('REDIS_HOST'),
'PASSWORD' : os.environ.get('REDIS_PASSWORD', None),
'PORT' : int(os.environ.get('REDIS_PORT', 6379)),
'DB' : int(os.environ.get('REDIS_DB', 0)),
}
WEBSOCKET_URL = os.environ.get('WEBSOCKET_URL')
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['XX.com','production.XX.com','www.XX.com',]
SESSION_COOKIE_DOMAIN = '.XX.com'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = os.environ.get('MEDIA_ROOT')
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = os.environ.get('STATIC_ROOT')