
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Configure Django using environment variables (envvars). settings.py
optional.
python -m pip install django-envconfig
Edit the manage.py
, asgi.py
and wsgi.py
files generated by Django's
startproject
command and modify the following line:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envconfig.settings')
The following envvars are required (if settings.py
is removed):
ALLOWED_HOSTS
(unless you set DEBUG=on
)Environments may be stored in an .env
file. This file can be stored in your
root directory (next to manage.py
) or anywhere on the path (e.g. virtualenv
directory).
Any Django setting can be configured as an environment variable.
true|yes|on|1
and false|no|off|0
(case-insensitive)None
: none|null
(case-insensitive)export ALLOWED_HOSTS=127.0.0.1,localhost
Settings are loaded with the following priority (highest first):
settings.py
, if it exists. Note: any
custom settings should be defined here with their default value.settings.py
file generated by
startproject
. This should eliminate the need for the file in (2) for most
projects. Caveats:
DEBUG
has been changed to False
.SECRET_KEY
is generated but will not persist between sessions (e.g.
if you restart your server/process manager). Check the
Django documentation
to see whether you need to set a persistent SECRET_KEY
as an
environment variable.Helper environment variables to use with django-envconfig:
Environment variable | Description |
---|---|
DJANGO_PROJECT | May be required if django-envconfig cannot find your project. Set to the name of the module originally generated by startproject |
ADD_INSTALLED_APPS | Add to INSTALLED_APPS |
REMOVE_INSTALLED_APPS | Remove from INSTALLED_APPS |
ADD_MIDDLEWARE | Add to MIDDLEWARE |
REMOVE_MIDDLEWARE | Remove from MIDDLEWARE |
If you are using a PostgreSQL backend you do not need to set DATABASES
. You
can simply set PostgreSQL environment variables - the minimum is PGDATABASE
.
See the
PostgreSQL docs
for the full list of envvars. This way the same environment can be used when
calling
PostgreSQL command line utilities
such as psql
or pg_dump
.
settings.py
up to date between Django versions.MIT.
FAQs
Configure Django using environment variables.
We found that django-envconfig demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.