Django Split Settings

1.3.2 · active · verified Thu Apr 16

django-split-settings helps organize Django settings into multiple files and directories, allowing for easier overriding and modification. It supports wildcards, optional settings files, and includes/merges settings from various sources. The current version is 1.3.2, with a release cadence that addresses bugfixes and adds support for newer Python and Django versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a typical setup for django-split-settings. In your `settings/__init__.py` file (or directly in your main `settings.py`), you import `include` and `optional`. You then use `include` to pull in other settings files, often starting with a `base.py` for common configurations, followed by environment-specific or local override files. The `optional()` wrapper ensures that your application doesn't crash if an included file (e.g., a developer's `local.py`) doesn't exist.

import os
from split_settings.tools import include, optional

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Include settings from base.py
include(optional('base.py'))

# Include environment-specific settings (e.g., local.py, production.py)
# The '*' wildcard includes all matching files.
# Using 'optional' prevents errors if a file doesn't exist.
# 'settings/*' would include files in a 'settings' subdirectory.
include(
    optional('environment/*.py'),
    optional('local.py')
)

# Example of a setting, potentially overridden by included files
DEBUG = True

ALLOWED_HOSTS = ['*']

# Example of how you might structure settings files:
#
# settings/
# ├── __init__.py  (This file)
# ├── base.py      (Common settings)
# ├── environment/
# │   ├── dev.py   (Development environment settings)
# │   └── prod.py  (Production environment settings)
# └── local.py     (Local overrides, usually excluded from VCS)

view raw JSON →