From 408c406abca13e621c9cfbf84887664df98b97aa Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 18 Apr 2015 04:09:41 -0400 Subject: [PATCH] Added a function for SECRET_KEY generation logic. --- django/core/management/commands/startproject.py | 6 +++--- django/core/management/utils.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/django/core/management/commands/startproject.py b/django/core/management/commands/startproject.py index f9c89d7493..f50f27cf1f 100644 --- a/django/core/management/commands/startproject.py +++ b/django/core/management/commands/startproject.py @@ -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) diff --git a/django/core/management/utils.py b/django/core/management/utils.py index 08efe11c87..637091e68a 100644 --- a/django/core/management/utils.py +++ b/django/core/management/utils.py @@ -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)