Last active
September 8, 2022 23:47
-
-
Save mattseymour/9205591 to your computer and use it in GitHub Desktop.
Django secret key generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Pseudo-random django secret key generator. | |
- Does print SECRET key to terminal which can be seen as unsafe. | |
""" | |
import string | |
import random | |
from __future__ import print_function | |
# 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('\\', '') | |
SECRET_KEY = ''.join([random.SystemRandom().choice(chars) for i in range(50)]) | |
print(SECRET_KEY) |
I made pip installation to generate django secret key https://github.com/ariestiyansyah/django-secret-key
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should move
from __future__ import print_function
to top of theimport string
. Current code is trowingSyntaxError: from __future__ imports must occur at the beginning of the file
exception