次のアプリ設定が与えられた場合:
/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')