Skip to content

Instantly share code, notes, and snippets.

@sandervm
Last active April 22, 2022 15:15
Show Gist options
  • Save sandervm/2b15775012685553f0e2 to your computer and use it in GitHub Desktop.
Save sandervm/2b15775012685553f0e2 to your computer and use it in GitHub Desktop.
Generate Django secret key commandline
$ python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'
Copy link

ghost commented Jun 26, 2020

Using Mr. Ioa's suggestion I was able to generate a secret key. However when I ran again 'docker-compose down", it threw this error

ERROR: environment variable name 'SECRET_KEY ' may not contains whitespace.

Any suggestion how to fix that.

@avvijeet
Copy link

@halfprisoner 'SECRET_KEY ' there is a trailing white space in your env variable

Also, how did you store the random key generated above into a variable before passing it as an env variable in the docker run of your project?

@s3rgeym
Copy link

s3rgeym commented Dec 1, 2021

Лучше бы ты написал как из SECRET_KEY сгенерировать куку

@millerthegorilla
Copy link

This is how django does it internally, translated into bash...

KEY=$(chars='abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'; python -c "import secrets; print(''.join(secrets.choice('${chars}') for i in range(50)))")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment