Attempt to fix django integration using a patch
approach.
#126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: #89
To help testing do:
now follow Instructions:
Django Extension
Dynaconf extensions for Django works by patching the
settings.py
file with dynaconf loading hooks, the change is done on a single file and then in your whole project every time you calldjango.conf.settings
you will have access todynaconf
attributes and methods.Initialize the extension
On the same directory where your
manage.py
is located run:Dynaconf will append a patch to the bottom of your settings file.
Or you can manually append at the bottom of your django project's
settings.py
the following code:Use
DJANGO_
environment variablesThen django.conf.settings will work as a
dynaconf.settings
instance andDJANGO_
will be the global prefix to export environment variables.Example:
Settings files
You can also have settings files for your Django app, in the root directory (the same where
manage.py
is located) put yoursettings.toml
and.secrets.toml
files and then define your environments[default]
,[development]
and[production]
.To switch the working environment the
DJANGO_ENV
variable can be used, soDJANGO_ENV=development
to workin development mode or
DJANGO_ENV=production
to switch to production.IF you don't want to manually create your config files take a look at the CLI
Customizations
It is possible to customize how your django project will load settings, example: You want your users to customize a settings file defined in
export PROJECTNAME_SETTINGS=/path/to/settings.toml
and you want environment variables to be loaded fromPROJECTNAME_VARNAME
Edit django
settings.py
and modify the dynaconf patch part:Then the working environment can now be switched using
export PROJECTNAME_ENV=production
And you can have user to define custom config files on
export PROJECTNAME_SETTINGS=/other/path/to/settings.py{yaml,toml,json,ini}
And users can set variables on environment like
export PROJECTNAME_DEBUG=true
Deprecation note
On old dynaconf releases the solution was to add
dynaconf.contrib.django_dynaconf
toINSTALLED_APPS
as the first item, this still works but has some limitations so it is not recommended anymore.