Skip to content

Instantly share code, notes, and snippets.

@Colk-tech
Last active March 3, 2022 10:57
Show Gist options
  • Save Colk-tech/b55be9e9de848f403dab8a0d04f8376e to your computer and use it in GitHub Desktop.
Save Colk-tech/b55be9e9de848f403dab8a0d04f8376e to your computer and use it in GitHub Desktop.
A Python script generates secret key of Django with specified length
from django.utils.crypto import get_random_string
def get_random_specified_length_secret_key(length: int) -> str:
"""
Return a random string with specified length usable as a SECRET_KEY setting value.
"""
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
return get_random_string(length, chars)
if __name__ == "__main__":
length: int = 128
print(get_random_specified_length_secret_key(length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment