Separate django settings for multiple environments
See also: https://www.coderedcorp.com/blog/django-settings-for-multiple-environments/
myproject/
env.py -- detect the environment
settings/
__init__.py -- settings entry(load specific settings based on env)
base.py -- shared common settings
dev.py -- development-only settings
prod.py -- production-only settings
myproject/env.py
import os
# Default to dev for safety.
APP_ENV = os.environ.get('APP_ENV', 'dev')
settings/__init__.py
from myproject.env import APP_ENV
if APP_ENV in ('dev', 'prod'):
exec('from .%s import *' % APP_ENV)
settings/base.py
# ...
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
# ...
settings/dev.py
from .base import *
DEBUG = True
# ...
settings/prod.py
from .base import *
DEBUG = False
# ...
APP_ENV=dev python manage.py runserver