This is a quick post - starting with Python 3.6, a
secrets module is included “for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets”. This means we can generate good values for Django’s
SECRET_KEY setting on any system with Python installed:
import secrets print(secrets.token_urlsafe())
python3 -c "import secrets;print(secrets.token_urlsafe())"
Previously, the usual method was to use Django’s built-in generator but that required Django to be installed on the machine being used to generate the secret:
from django.core.management.utils import get_random_secret_key print(get_random_secret_key())