Skip to content

Instantly share code, notes, and snippets.

@SafeEval
Last active August 29, 2015 14:18
Show Gist options
  • Save SafeEval/3a86e401db8e0311ba12 to your computer and use it in GitHub Desktop.
Save SafeEval/3a86e401db8e0311ba12 to your computer and use it in GitHub Desktop.
Generate a SECRET_KEY for Django via CLI
# Generates and prints a new SECRET_KEY for Django to STDOUT.
# Run directly from the command line without requiring a script file.
python -c "import random; import string; print (''.join( [random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation).replace('\"', '').replace('\'','') for i in range(100)] ))"
# Environment variable example.
# $ export SECRET_KEY=$(python -c "import random; import string; print (''.join( [random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation).replace('\"', '').replace('\'','') for i in range(100)] ))")
# Heroku example.
# $ heroku config:set SECRET_KEY=$(python -c "import random; import string; print (''.join( [random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation).replace('\"', '').replace('\'','') for i in range(100)] ))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment