Configure Django using environment variables.
Project description
django-envconfig
Configure Django using environment variables. Having a settings.py
file is
optional.
Getting started
Installation
python -m pip install django-envconfig
Usage
Edit the manage.py
, asgi.py
and wsgi.py
files generated by Django's
startproject
command and change the following line:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envconfig.settings')
Minimum configuration
The following environment variable is required:
export DJANGO_PROJECT=my_project_name
In the absence of a settings.py
file the following environment variables are
required: ALLOWED_HOSTS
and either DATABASES
or PGDATABASE
.
Environments may be stored in an .env
file. This file can be stored in your
root directory (same as manage.py
) or anywhere on the path (e.g. virtualenv
directory).
How it works
Any Django setting can be configured as an environment variable.
- To set a boolean:
true|yes|on|1
andfalse|no|off|0
(case-insensitive) - To set
None
:none|null
(case-insensitive) - Simple lists of strings can be stored comma-separated e.g.
export ALLOWED_HOSTS=127.0.0.1,localhost
- Dicts and complex lists should be stored as JSON
Settings are loaded with the following priority (highest first):
- Environment variables.
- Settings defined in your projects
settings.py
, if it exists. - Settings that would be defined by a
settings.py
file generated bystartproject
. This should eliminate the need for the file in most projects. Two main caveats:- The default value for
DEBUG
has been changed toFalse
. - A
SECRET_KEY
is generated but will not persist between sessions (e.g. if you restart your server/process manager). This may or may not be an issue depending on your use case - see the Django documentation for more details.
- The default value for
If you are using a PostgreSQL backend you do not need to specify a DATABASES
setting if you have set PostgreSQL environment variables - the minimum is
PGDATABASE
. See the PostgreSQL docs
for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-envconfig-0.1.1.tar.gz
.
File metadata
- Download URL: django-envconfig-0.1.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ed5e5f189dd1fa823ac041944ccc6bb46e938fd68ab5146522864471ced9639 |
|
MD5 | 52fd6b66ef0267c4c1e500d1849c015c |
|
BLAKE2b-256 | 97c6282a80cc85b2700252da8ae5d952caeec1113e93ec9a0fd2197a4d57156b |
File details
Details for the file django_envconfig-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_envconfig-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a3962fe11e27d401fae3acb4e41679c6defd6fbd858eb3273f5e13152f2557 |
|
MD5 | 7ac62c7c40b437fc8d4cf36cbc6abd64 |
|
BLAKE2b-256 | da570c82111b497a816cf73e25c8e10d72bf03d4c258368931250aeeb82accd3 |