This project has been archived by its maintainers, and is no longer receiving any updates.
django-settings-file
Unmaintained (2022-12-07)
I stopped maintaining this package as it has never been popular. If you want to use the functionality I recommend copying the small amount of code into your project.
Let Django use settings from an arbitrary Python file instead of an importable module.
As per James Pic’s idea posted on the django-developers mailing list.
Requirements
Python 3.7 to 3.11 supported.
Django 3.2 to 4.1 supported.
Want to work smarter and faster? Check out my book Boost Your Django DX which covers many ways to improve your development experience.
Usage
Install with python -m pip install django-settings-file.
Edit your manage.py and wsgi.py to swap out Django’s default logic for setting DJANGO_SETTINGS_MODULE to instead do:
import django_settings_file django_settings_file.setup()Add os.environ.setdefault('DJANGO_SETTINGS_FILE', '/path/to/default.py') before the setup() call, unless you can be sure DJANGO_SETTINGS_FILE will always be defined in your environment. You might need to figure out the path relative to your manage.py with some os.path manipulation.
Run it! If DJANGO_SETTINGS_MODULE is defined, it will raise a DjangoSettingsFileError with a message about how only DJANGO_SETTINGS_FILE is allowed now. If DJANGO_SETTINGS_FILE is not defined, it will also fail with a DjangoSettingsFileError with a message about defining it. Otherwise Django should start with the settings!
How it works
django-settings-file imports the contents of the specified file using the import machinery available on your Python version (different logic for 2 and 3) and copies it contents into its own module, which Django sees as the settings file defined via the traditional DJANGO_SETTINGS_MODULE. Nothing about Django is really touched, it’s just a hacky module.
Caveats
If the Python file defined by DJANGO_SETTINGS_FILE tries to do any imports, the directory the file is in will not be on PYTHONPATH, so the author of the settings file might get some surprises.
Additionally, you might experience other problems from loading a file whilst it’s not on PYTHONPATH.
If you want your settings file to extend another one, it will probably find it easiest to import the base one from a location on PYTHONPATH, otherwise it too will have to do use the same import ‘hacks’ to load the default settings.
File paths are not portable between operating systems, so you may need logic to support both Unix and Windows at once.
File paths are not portable between .py and .pyc files. In most cases this means a .pyc file will not be used for settings since it can’t be guaranteed to be there, slightly slowing down import time.
DJANGO_SETTINGS_MODULE and DJANGO_SETTINGS_FILE can’t both be used by the same project, since the module is required for the file-based logic. You might be able to allow them both with extra logic, pull requests accepted.
¯\_(ツ)_/¯ - this is kind of unknown territory, this library has not been tested in any real project, just with the example project in the test folder.
Metadata
Release files for django-settings-file 2.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-settings-file-2.10.1.tar.gz | 5.7 kB | Without provenance | Details for django-settings-file-2.10.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_settings_file-2.10.1-py3-none-any.whl | Python 3 | none | any | Details for django_settings_file-2.10.1-py3-none-any.whl |
Total release size: 10.9 kB
Release files / django-settings-file-2.10.1.tar.gz
| Download URL | django-settings-file-2.10.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
608d43cc6017b3cec81270d8014f5eebe400239188fdb81499d922edf9ff47d4
|
|
BLAKE2b-256 checksum How to use checksums |
3f37aecaa3d2b2a8eda0296118486c8ce752858f22a55761b151e9bc328af403
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / django_settings_file-2.10.1-py3-none-any.whl
| Download URL | django_settings_file-2.10.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
312695f5c14e542dbe79842562437c448c5c6aa0f4478dfd12cee2e5283df996
|
|
BLAKE2b-256 checksum How to use checksums |
0f95235e79c5c29ff30db4c4d5f76062416bd6c41ca8074b9775c9ebe8d5d8a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for django-settings-file 2.10.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.