Created
February 18, 2021 20:07
-
-
Save isoboroff/48986e7df9ae067fcfd6c62d3c911385 to your computer and use it in GitHub Desktop.
Django ./manage.py command to generate secret keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand, CommandError | |
from django.utils.crypto import get_random_string | |
class Command(BaseCommand): | |
help='''Generate a secret key the same way Django does. | |
You will need to install it either in settings.py for dev or externally for production | |
''' | |
def add_arguments(self, parser): | |
parser.add_argument('-l', '--length', type=int, default=50) | |
def handle(self, *args, **options): | |
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | |
return get_random_string(options['length'], chars) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment