.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
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.Save the output as .env in your project root (next to manage.py).
- 2.Install python-dotenv: pip install python-dotenv.
- 3.Load it at the top of settings.py: load_dotenv() after importing.
- 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
DEBUGNever True in production. Leaks stack traces and settings.
SECRET_KEYDjango's signing key. Rotate per environment.
ALLOWED_HOSTSComma-separated domains. Required when DEBUG=False.
DATABASE_URLPostgres connection string, parsed by dj-database-url.
REDIS_URLRedis for cache + sessions.
CELERY_BROKER_URLCelery task queue backend (often the same Redis).
Related tools
Other stacks
Node.js .env
/env-generator/nodejs
Next.js .env
/env-generator/nextjs
Ruby on Rails .env
/env-generator/rails
React (Vite) .env
/env-generator/react
Python (FastAPI / Flask) .env
/env-generator/python
Go .env
/env-generator/go
Docker Compose .env
/env-generator/docker
Kubernetes .env
/env-generator/kubernetes
Stripe .env
/env-generator/stripe
Firebase .env
/env-generator/firebase
Supabase .env
/env-generator/supabase
OpenAI .env
/env-generator/openai
Laravel .env
/env-generator/laravel