Managing Django’s settings

Nikita Sobolev
Apr 1, 2017 · 3 min read
Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.
try:
from local_settings import *
except ImportError:
# No local settings was found, skipping.
pass

How-to

How does django-split-settings solve these issues? This helper provides a user-friendly interface to store your settings in different files. Let’s look at the example. Imagine you have an existing project with django, postgres, redis , rq, and emails.

your_project/settings/
├── __init__.py
├── components
│ ├── __init__.py
│ ├── database.py
│ ├── common.py
│ ├── emails.py
│ ├── rq.py
└── environments
├── __init__.py
├── development.py
├── local.py.template
├── production.py
└── testing.py
Code example

  1. We now have separated settings based on environment
  2. We now have optional local settings with now dirty hacks
  3. We did not have to do any refactoring except just some basic restructuring

What’s not covered

In a future articles we would cover two topics which are crucial when dealing with project’s configuration:

  1. Dynamic settings

Afterword

Got any ideas or feedback? Dive in, if you want to contribute:

wemake.services

We love Python and Elixir. We use Javascript.

Nikita Sobolev

Written by

wemake.services co-founder, ElixirLangMoscow co-organizer, open source developer

wemake.services

We love Python and Elixir. We use Javascript.