Skip to content

Instantly share code, notes, and snippets.

@julianobarbosa
Created June 26, 2019 13:46
Show Gist options
  • Save julianobarbosa/9368f55c0a51540d1fff90a676f26680 to your computer and use it in GitHub Desktop.
Save julianobarbosa/9368f55c0a51540d1fff90a676f26680 to your computer and use it in GitHub Desktop.
contrib env_gen.py - Create environment variables to use with settings of Django
#!/usr/bin/env python
"""
Django SECRET_KEY generator.
"""
from django.utils.crypto import get_random_string
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
CONFIG_STRING = """
DEBUG=True
SECRET_KEY=%s
ALLOWED_HOSTS=127.0.0.1, .localhost
#DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME
#DEFAULT_FROM_EMAIL=
#EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
#EMAIL_HOST=
#EMAIL_PORT=
#EMAIL_USE_TLS=
#EMAIL_HOST_USER=
#EMAIL_HOST_PASSWORD=
""".strip() % get_random_string(50, chars)
# Writing our configuration file to '.env'
with open('.env', 'w') as configfile:
configfile.write(CONFIG_STRING)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment