Skip to content

Instantly share code, notes, and snippets.

@zerodi
Forked from mattseymour/django-secret-keygen.py
Last active November 5, 2015 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerodi/f742dc0a8fb28e852ceb to your computer and use it in GitHub Desktop.
Save zerodi/f742dc0a8fb28e852ceb to your computer and use it in GitHub Desktop.
Django secret key generator
from __future__ import print_function
"""
Pseudo-random django secret key generator.
- Does print SECRET key to terminal which can be seen as unsafe.
"""
import string
import random
# Get ascii Characters numbers and punctuation (minus quote characters as they could terminate string).
chars = ''.join([string.ascii_letters, string.digits, string.punctuation]).replace('\'', '').replace('"', '').replace('\\', '').replace('`', '')
SECRET_KEY = ''.join([random.SystemRandom().choice(chars) for i in range(50)])
print(SECRET_KEY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment