Slide 1

Slide 1 text

Stop writing settings files

Slide 2

Slide 2 text

Settings

Slide 3

Slide 3 text

local_settings # settings.py # settings goes here, and at the end… try: from local_settings import * except ImportError: pass

Slide 4

Slide 4 text

# settings.py INSTALLED_APPS = … # local_settings.py INSTALLED_APPS = … How do I know what's in the base settings?

Slide 5

Slide 5 text

# settings/base.py INSTALLED_APPS = … # settings/production.py from .base import * # override here with # production-specific settings Multiple settings files $ python manage.py shell --settings=settings.production

Slide 6

Slide 6 text

settings/ __init__.py base.py dev.py staging.py production.py other.py stuff.py whatever.py

Slide 7

Slide 7 text

— 12factor.net " " … strict separation of config from code. Config varies substantially across deploys,code does not.

Slide 8

Slide 8 text

Expose your configuration as environment variables Derive your settings from the environment DEBUG = bool(os.environ.get('DEBUG', False)) Use one settings file

Slide 9

Slide 9 text

ALLOWED_HOSTS AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY DATABASE_URL DJANGO_SETTINGS_MODULE EMAIL_URL FROM_EMAIL HTTPS MEDIA_ROOT REDIS_URL SECRET_KEY SENTRY_DSN STATIC_ROOT

Slide 10

Slide 10 text

What about development? Aren't environment variables a pain to work with?

Slide 11

Slide 11 text

daemontools' envdir path/to/env/ DATABASE_URL SENTRY_DSN … $ envdir path/to/env $ envdir path/to/env django-admin.py Sane defaults for development kept under version control

Slide 12

Slide 12 text

envdir in ur manage.py if __name__ == "__main__": if 'test' in sys.argv: env_dir = os.path.join('tests', 'envdir') else: env_dir = 'envdir' env_vars = glob.glob(os.path.join(env_dir, '*')) for env_var in env_vars: with open(env_var, 'r') as env_var_file: os.environ.setdefault(env_var.split(os.sep)[-1], env_var_file.read().strip()) from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)

Slide 13

Slide 13 text

One settings files, less moving parts Configuration as environment variables Production: set them with daemontools, circus, supervisor… Development: use envdir and/or a custom manage.py Your PaaS already supports them Easy to setup with Salt/Puppet/Chef Your sysadmin will thank you

Slide 14

Slide 14 text

thanks! @brutasse