tool

Django Secret Key Generator

Generate a production-ready SECRET_KEY for Django using the same character set as Django's own get_random_secret_key(). Everything runs locally in your browser.

Django SECRET_KEY (50 chars)
Matches Django's get_random_secret_key() charset
Raw secret
.env line
SECRET_KEY=
CLI alternative (Python)
from django.core.management.utils import get_random_secret_key print(get_random_secret_key())

What is Django's SECRET_KEY?

Django's SECRET_KEY is used to sign cryptographic hashes for sessions, CSRF tokens, password reset links, and any value you pass through Django's signing framework. A weak or compromised key can allow attackers to forge any of these values.

Django requires the key to be at least 50 characters long, drawn from letters, digits, and a safe set of symbols: !@#$%^&*(-_=+). This tool uses exactly that charset.

How to add it to your project

  1. Copy the generated key and paste it into your .env:
    SECRET_KEY=<paste here>
  2. Load it in settings.py using python-decouple or django-environ:
    import environ
    env = environ.Env()
    SECRET_KEY = env("SECRET_KEY")
  3. Never hardcode SECRET_KEY in settings.py and never commit the .env file.

Rotating the key

Rotating SECRET_KEY invalidates all existing sessions, password-reset links, and CSRF tokens immediately. Plan a maintenance window or use Django's SECRET_KEY_FALLBACKS (Django 4.1+) to support both old and new keys during a transition.

Related tools