Skip to content

Instantly share code, notes, and snippets.

@electroniceagle
Created January 15, 2014 20:50
Show Gist options
  • Save electroniceagle/8444359 to your computer and use it in GitHub Desktop.
Save electroniceagle/8444359 to your computer and use it in GitHub Desktop.
This code snippet takes a Django secret from an environment variable or generates a random one automatically exactly once for testing. This hasn't been tested with multiple processes, so might not work as expected in a situation such as running a Celery daemon.
# use secret from environment or make a random one exactly once
SECRET_KEY = os.environ.get(
'DJANGO_SECRET',
os.environ.update({
'DJANGO_SECRET': ''.join([random.SystemRandom().choice(
string.digits + string.letters + string.punctuation)
for i in range(50)])}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment