• Stars
    star
    1,031
  • Rank 43,053 (Top 0.9 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created almost 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.

django-split-settings logo


wemake.services test codecov Docs Python Version wemake-python-styleguide

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards in settings file paths and mark settings files as optional.

Read this blog post for more information. Also, check this example project.

Requirements

While this package will most likely work with the most versions of django, we officially support:

  • 3.2
  • 4.0
  • 4.1

This package has no dependencies itself.

In case you need older python / django versions support, then consider using older versions of django-split-settings.

Installation

pip install django-split-settings

Usage

Replace your existing settings.py with a list of components that make up your Django settings. Preferably create a settings package that contains all the files.

Here's a minimal example:

from split_settings.tools import optional, include

include(
    'components/base.py',
    'components/database.py',
    optional('local_settings.py')
)

In the example, the files base.py and database.py are included in that order from the subdirectory called components/. local_settings.py in the same directory is included if it exists.

Note: The local context is passed on to each file, so each following file can access and modify the settings declared in the previous files.

We also made an in-depth tutorial.

Tips and tricks

You can use wildcards in file paths:

include('components/my_app/*.py')

Note that files are included in the order that glob returns them, probably in the same order as what ls -U would list them. The files are NOT in alphabetical order.

You can modify common settings in environment settings simply importing them

# local_settings.py
from components.base import INSTALLED_APPS

INSTALLED_APPS += (
  'raven.contrib.django.raven_compat',
)

Updating BASE_DIR

The django create-project command will create a variable in your settings.py called BASE_DIR, which is often used to locate static files, media files, and templates.

# Created by django create-project
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles/")
MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles/")

The expression for BASE_DIR means: get the path to the current file (settings.py), get the parent folder (whatever you named your project), get the parent folder (the root of the project). So STATIC_ROOT will then be evaluated to /staticfiles (with / meaning the root of your project/repo).

With django-split-settings settings is now a module (instead of a file), so os.path.dirname(os.path.dirname(os.path.abspath(__file__))) will evaluate to /whatever-you-named-your-project as opposed to /.

To fix this BASE_DIR needs to be set to the parent folder of /whatever-you-named-your-project:

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

Do you want to contribute?

Read the CONTRIBUTING.md file.

Version history

See CHANGELOG.md file.

More Repositories

1

wemake-python-styleguide

The strictest and most opinionated python linter ever!
Python
2,417
star
2

wemake-django-template

Bleeding edge django template focused on code quality and security.
Python
1,933
star
3

wemake-vue-template

Bleeding edge vue template focused on code quality and developer happiness.
TypeScript
730
star
4

django-test-migrations

Test django schema and data migrations, including migrations' order and best practices.
Python
490
star
5

wemake-python-package

Bleeding edge cookiecutter template to create new python packages
Python
395
star
6

flake8-eradicate

Flake8 plugin to find commented out or dead code
Python
304
star
7

dotenv-linter

☺️ Linting dotenv files like a charm!
Python
270
star
8

caddy-gen

Automated Caddy reverse proxy for docker containers
Shell
229
star
9

recase

♻️ Convert strings to any case.
Elixir
215
star
10

nuxt-imagemin

Nuxt module to minify your images. Works with: png, jpeg, gif, and svg
JavaScript
178
star
11

ecto_autoslug_field

Automatically create slugs for Ecto schemas.
Elixir
147
star
12

jekyll-theme-hackcss

Dead simple CSS framework now with Jekyll.
HTML
123
star
13

docker-image-size-limit

🐳 Keep an eye on your docker image size and prevent it from growing too big
Python
113
star
14

flake8-broken-line

🚨 Flake8 plugin to forbid backslashes (\) for line breaks
Python
108
star
15

kira-dependencies

🐿 Kira's micro-bot to update project dependencies
Ruby
102
star
16

dump-env

A utility tool to create .env files
Python
97
star
17

wemake-frontend-styleguide

Set of the strictest linters for your next frontend app
JavaScript
74
star
18

kira

🐿️ Project management framework with deep philosophy underneath
Elixir
69
star
19

coverage-conditional-plugin

Conditional coverage based on any rules you define!
Python
63
star
20

meta

Home of Repeatable Software Development Process
HTML
51
star
21

pravda

Python type-checker written in Rust
Makefile
33
star
22

nuxt-babel

Use normal .babelrc file with your Nuxt app
JavaScript
33
star
23

asyncio-redis-rate-limit

Rate limiter for async functions using Redis as a backend.
Python
30
star
24

vue-material-input

Simple implementation of Material Input with no dependencies
Vue
24
star
25

vue-analytics-facebook-pixel

A small wrapper around Facebook Pixel API
JavaScript
23
star
26

mypy-extras

A collection of extra types and features for mypy
Python
22
star
27

caddy-docker

Docker image for Caddy
Dockerfile
19
star
28

awesome-microtasking

List of awesome resources and companies that practice microtasking
15
star
29

jinja2-git

Jinja2 extension to handle git-specific things
Python
15
star
30

safe-assert

Safe and composable assert for Python that can be used together with optimised mode
Python
13
star
31

kira-stale

🐿️ Kira's micro-bot to fight with stale GitLab issues and merge requests
Procfile
13
star
32

pytest-modified-env

Pytest plugin to fail a test if it leaves modified `os.environ` afterwards.
Python
11
star
33

vue-material-ripple

Simple material ripple effect wrapped in a component
Vue
11
star
34

remark-lint-are-links-valid

This package allows to perform multiple checks on your links
JavaScript
11
star
35

wemake-django-rest

Create Django REST APIs the right way, no magic intended
HTML
11
star
36

wemake-dind

Our docker-in-docker image with Python
Dockerfile
10
star
37

stylelint-config-strict-scss

Deprecated, use wemake-frontend-styleguide instead
JavaScript
8
star
38

kira-review

🐿️ Kira's micro-bot to review merge requests before real humans
Ruby
7
star
39

django-pre-deploy-checks

Django checks that you should run on application deploy
Python
5
star
40

mimesis-cloud

Python
5
star
41

kira-release

🐿️ Kira's micro-bot to release your code and track changes
JavaScript
5
star
42

vue-material-radio

Simple implementation of Material Radio Button with no dependencies
Vue
4
star
43

eslint-config-flowtype-essential

Deprecated, use wemake-frontend-styleguide instead
JavaScript
4
star
44

kira-setup

🐿 Kira's micro-bot to setup new projects
Python
3
star
45

remark-lint-list-item-punctuation

This package allows to check either a list item ends with a period.
JavaScript
3
star
46

eslint-config-jsdoc-essential

Deprecated, use wemake-frontend-styleguide instead
JavaScript
2
star
47

.github

GitHub metadata
1
star
48

wemake-services.github.io

Company's website. As minimal as possible.
JavaScript
1
star