Django Secret Key Generator
DJANGO_SECRET_KEY
Generating in your browser…
Generated on your device with the Web Crypto API. Never sent or stored.
DJANGO_SECRET_KEY=""Prefer the terminal?
- Django
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
How to use your Django SECRET_KEY
Copy the value above and add it to your environment as DJANGO_SECRET_KEY and read it in settings.py with os.environ. Keep it out of source control: commit an .env.example with an empty value instead, and set the real value in your hosting provider's environment settings or a secrets manager.
Django uses SECRET_KEY for sessions, password-reset tokens, messages and anything signed with django.core.signing. The key on this page uses the same 50-character alphabet as get_random_secret_key(). If you need to rotate without logging everyone out, put the old key in SECRET_KEY_FALLBACKS (Django 4.1+) for a while.
Is it safe to generate secrets in a browser?
Only if the secret is created locally, which is how this page works. The value comes from crypto.getRandomValues, the same cryptographically secure source browsers use for TLS keys, and it never leaves your device: there is no network request, log or analytics event that includes it.
If you prefer the command line, the commands on this page produce an equivalent secret on your own machine. Either way, use a different secret for development, staging and production, and rotate it straight away if it ever appears in a log, a screenshot or a public repository.
Frequently asked questions
What happens if I change SECRET_KEY?
Existing sessions, password-reset links and signed cookies become invalid. Users will need to log in again unless you keep the old key in SECRET_KEY_FALLBACKS.