· 9 years ago · Jan 10, 2017, 06:56 PM
1"""
2Pseudo-random django secret key generator.
3- Does print SECRET key to terminal which can be seen as unsafe.
4"""
5from __future__ import print_function
6import string
7import random
8
9# Get ascii Characters numbers and punctuation (minus quote characters as they could terminate string).
10chars = ''.join([string.ascii_letters, string.digits, string.punctuation]).replace('\'', '').replace('"', '').replace('\\', '')
11
12SECRET_KEY = ''.join([random.SystemRandom().choice(chars) for i in range(50)])
13
14print(SECRET_KEY)