Skip to content

Instantly share code, notes, and snippets.

@rg3915
Last active April 18, 2021 01:30
Show Gist options
  • Save rg3915/75eed74f3578ac0dde808b1194b0e486 to your computer and use it in GitHub Desktop.
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
"""
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