Generating Secret Keys
OpenSSL
openssl rand -base64 32
Using Django
shell_secret_key.sh
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
From the Django Shell
django_shell_key.sh
python manage.py shell
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
Base-64 Encoded Django Secret Key
If you need a Base64 encoded version like for Kubernetes or Knative, use the following commands:
base_64_secret_key.sh
export SECRET_KEY=$(python -c "from django.core.management.utils import get_random_secret_key;print(get_random_secret_key())")
echo "Secret key is: $SECRET_KEY"
export SECRET_KEY_ENCODED=$(echo "$SECRET_KEY" | base64)
echo "Base64 Encoded Secret key is: $SECRET_KEY_ENCODED"