1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Added a function for SECRET_KEY generation logic.

This commit is contained in:
Roberto Rosario 2015-04-18 04:09:41 -04:00 committed by Tim Graham
parent f2b45ddd99
commit 408c406abc
2 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,8 @@ from importlib import import_module
from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand
from django.utils.crypto import get_random_string
from ..utils import get_random_secret_key
class Command(TemplateCommand):
@ -27,7 +28,6 @@ class Command(TemplateCommand):
project_name)
# Create a random SECRET_KEY to put it in the main settings.
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
options['secret_key'] = get_random_string(50, chars)
options['secret_key'] = get_random_secret_key()
super(Command, self).handle('project', project_name, target, **options)

View File

@ -5,6 +5,7 @@ import sys
from subprocess import PIPE, Popen
from django.utils import six
from django.utils.crypto import get_random_string
from django.utils.encoding import DEFAULT_LOCALE_ENCODING, force_text
from .base import CommandError
@ -75,3 +76,11 @@ def find_command(cmd, path=None, pathext=None):
if os.path.isfile(fext):
return fext
return None
def get_random_secret_key():
"""
Return a 50 character random string usable as a SECRET_KEY setting value.
"""
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
return get_random_string(50, chars)