· 7 years ago · Feb 13, 2018, 12:50 AM
1"""
2Pseudo-random django secret key generator.
3- Does print SECRET key to terminal which can be seen as unsafe.
4"""
5
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)