Die SECRET_KEY-Einstellung darf nicht leer sein || Erhältlich Settings.py

Habe ich nach diesem Fehler, aber nicht wissen, wie es zu lösen.

Ich immer die Fehlermeldung "Die SECRET_KEY-Einstellung darf nicht leer sein." bei der Ausführung populate_rango.py

Habe ich überprüft settings.py und der geheime Schlüssel ist bereits eingefügt.

Hier ist die komplette Fehlermeldung:

E:\PythonCode\django1\tango_with_django>python populate_rango.py
Starting Rango population script...
Traceback (most recent call last):
  File "populate_rango.py", line 27, in <module>
    from rango.models import Category, Page
  File "E:\PythonCode\django1\tango_with_django\rango\models.py", line 1, in <mo
dule>
    from django.db import models
  File "C:\python27\lib\site-packages\django\db\models\__init__.py", line 5, in
<module>
    from django.db.models.query import Q
  File "C:\python27\lib\site-packages\django\db\models\query.py", line 17, in <m
odule>
    from django.db.models.deletion import Collector
  File "C:\python27\lib\site-packages\django\db\models\deletion.py", line 4, in
<module>
    from django.db.models import signals, sql
  File "C:\python27\lib\site-packages\django\db\models\sql\__init__.py", line 4,
 in <module>
    from django.db.models.sql.subqueries import *
  File "C:\python27\lib\site-packages\django\db\models\sql\subqueries.py", line
12, in <module>
    from django.db.models.sql.query import Query
  File "C:\python27\lib\site-packages\django\db\models\sql\query.py", line 22, i
n <module>
    from django.db.models.sql import aggregates as base_aggregates_module
  File "C:\python27\lib\site-packages\django\db\models\sql\aggregates.py", line
9, in <module>
    ordinal_aggregate_field = IntegerField()
  File "C:\python27\lib\site-packages\django\db\models\fields\__init__.py", line
 116, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 54, in __ge
tattr__
    self._setup(name)
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 49, in _set
up
    self._wrapped = Settings(settings_module)
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 151, in __i
nit__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be
empty.

E:\PythonCode\django1\tango_with_django>python populate_rango.py
Starting Rango population script...
Traceback (most recent call last):
  File "populate_rango.py", line 27, in <module>
    from rango.models import Category, Page
  File "E:\PythonCode\django1\tango_with_django\rango\models.py", line 1, in <mo
dule>
    from django.db import models
  File "C:\python27\lib\site-packages\django\db\models\__init__.py", line 5, in
<module>
    from django.db.models.query import Q
  File "C:\python27\lib\site-packages\django\db\models\query.py", line 17, in <m
odule>
    from django.db.models.deletion import Collector
  File "C:\python27\lib\site-packages\django\db\models\deletion.py", line 4, in
<module>
    from django.db.models import signals, sql
  File "C:\python27\lib\site-packages\django\db\models\sql\__init__.py", line 4,
 in <module>
    from django.db.models.sql.subqueries import *
  File "C:\python27\lib\site-packages\django\db\models\sql\subqueries.py", line
12, in <module>
    from django.db.models.sql.query import Query
  File "C:\python27\lib\site-packages\django\db\models\sql\query.py", line 22, i
n <module>
    from django.db.models.sql import aggregates as base_aggregates_module
  File "C:\python27\lib\site-packages\django\db\models\sql\aggregates.py", line
9, in <module>
    ordinal_aggregate_field = IntegerField()
  File "C:\python27\lib\site-packages\django\db\models\fields\__init__.py", line
 116, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 54, in __ge
tattr__
    self._setup(name)
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 49, in _set
up
    self._wrapped = Settings(settings_module)
  File "C:\python27\lib\site-packages\django\conf\__init__.py", line 151, in __i
nit__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be
empty.

Hier settings.py:

"""
Django settings for tango_with_django project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')

TEMPLATE_DIRS = (
    TEMPLATE_PATH,
    )

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'y130-j9oz4r5aoamn_n=+s-*7n)*3^s$jmf4(qw6ik28()g^(n'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rango',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'tango_with_django.urls'

WSGI_APPLICATION = 'tango_with_django.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

STATIC_PATH = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = (
    STATIC_PATH,
)

Hier ist die populate_rango.py:

import os

def populate():
    python_cat = add_cat('Python')

    add_page(cat=python_cat,
        title="Official Python Tutorial",
        url="http://docs.python.org/2/tutorial/")

    for c in Category.objects.all():
        for p in Page.objects.filter(category=c):
            print "- {0} - {1}".format(str(c),str(p))


def add_page(cat, title, url, views=0):
    p = Page.objects.get_or_create(category=cat, title=title, url=url, views=views)[0]
    return p

def add_cat(name):
    c = Category.objects.get_or_create(name=name)[0]
    return c

#start execution here
if __name__=='__main__':
    print "Starting Rango population script..."
    os.environ.setdefault('DJANGO_SETTINGS_MODULE','tango_with_django')
    from rango.models import Category, Page
    populate()
Ich denke, dass Sie möglicherweise fehlt eine .settings in Ihrem os.environ.setdefault. Was passiert, wenn Sie ändern Sie diese Zeile: os.environ.setdefault('DJANGO_SETTINGS_MODULE','tango_with_django.settings')
Ja, versuchen tango_with_django.settings wie deine Einstellungen Weg. Wenn das nicht funktioniert, können Sie Ihre Projekt-Verzeichnis-Struktur???
# SECURITY WARNING: keep the secret key used in production secret!. Stellen Sie sicher, dass der geheime Schlüssel nach dem dieses problem gelöst wurde.

InformationsquelleAutor Awan | 2014-05-04

Schreibe einen Kommentar