
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.
We support django
versions from 1.5
up to the most recent one.
Install by using pip
:
pip install django-split-settings
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.
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.
Windows only!
You can improve settings files loading speed if requirements are satisfied: * running on Windows 7 or above * pypiwin32 library installed
What you'll get - about 10-15% increase the speed of read operations:
# Testing file "test.bin" with size ~ 100 Kb
code = '''
with open("test.bin", "rb") as f:
data = f.read()
'''
loop_first = timeit.Timer(stmt=code)
setup = '''
from f_open.file import FastOpen
'''
code = '''
with FastOpen("test.bin") as file:
data = file.read()
'''
loop_second = timeit.Timer(stmt=code, setup=setup)
>>> print('Best of 3 open() running time: {} sec.'.format(min(loop_first.repeat(repeat=3, number=1000))))
>>> print('Best of 3 FastOpen running time: {} sec.'.format(min(loop_second.repeat(repeat=3, number=1000))))
Best of 3 open() running time: 0.08507176789928023 sec.
Best of 3 FastOpen running time: 0.07332583989214703 sec.
Read the contributing file.
See changelog file.