Last active
April 18, 2021 01:30
-
-
Save rg3915/75eed74f3578ac0dde808b1194b0e486 to your computer and use it in GitHub Desktop.
contrib env_gen.py just Python - contrib random - Create environment variables to use with settings of Django
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
""" | |
Python SECRET_KEY generator. | |
""" | |
import random | |
chars = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$%^&*()" | |
size = 50 | |
secret_key = "".join(random.sample(chars, size)) | |
chars = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$%_" | |
size = 20 | |
password = "".join(random.sample(chars, size)) | |
CONFIG_STRING = """ | |
DEBUG=True | |
SECRET_KEY=%s | |
ALLOWED_HOSTS=127.0.0.1,.localhost,0.0.0.0 | |
#DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME | |
#POSTGRES_DB= | |
#POSTGRES_USER= | |
#POSTGRES_PASSWORD=%s | |
#DB_HOST=localhost | |
#DEFAULT_FROM_EMAIL= | |
#EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend | |
#EMAIL_HOST=localhost | |
#EMAIL_PORT= | |
#EMAIL_HOST_USER= | |
#EMAIL_HOST_PASSWORD= | |
#EMAIL_USE_TLS=True | |
""".strip() % (secret_key, password) | |
# Writing our configuration file to '.env' | |
with open('.env', 'w') as configfile: | |
configfile.write(CONFIG_STRING) | |
print('Success!') | |
print('Type: cat .env') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment