
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.