.env · generator · Django

Django .env Generator

Django projects traditionally used settings.py for config, but that pattern leaks secrets into git. This generator produces a .env compatible with python-dotenv or django-environ — with Postgres, Redis, Celery, and SMTP already structured.

.env for Django · 8 keys
Customize →
DEBUG=True
SECRET_KEY=tDKpTTz9G8N5a-X0VhGF8ao6XnlbqbvdSFOeCu0TDPu4Nema
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=postgres://user:password@localhost:5432/mydb
REDIS_URL=redis://localhost:6379/0
CELERY_BROKER_URL=redis://localhost:6379/1
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Django

  1. 1.Save the output as .env in your project root (next to manage.py).
  2. 2.Install python-dotenv: pip install python-dotenv.
  3. 3.Load it at the top of settings.py: load_dotenv() after importing.
  4. 4.Read with os.environ["KEY"] or os.getenv("KEY", "default").

Gotchas

  • Read env vars at module-load time in settings.py — not inside functions — to fail fast.
  • SECRET_KEY must stay secret even in dev. Generate a new one per environment.
  • ALLOWED_HOSTS is comma-separated in .env, but must be a Python list in settings.py.

Common keys explained

DEBUG

Never True in production. Leaks stack traces and settings.

SECRET_KEY

Django's signing key. Rotate per environment.

ALLOWED_HOSTS

Comma-separated domains. Required when DEBUG=False.

DATABASE_URL

Postgres connection string, parsed by dj-database-url.

REDIS_URL

Redis for cache + sessions.

CELERY_BROKER_URL

Celery task queue backend (often the same Redis).

Related tools

Other stacks