配置不当:编辑 Django 身份验证管道后 SECRET_KEY 设置不能为空错误

ImproperlyConfigured: The SECRET_KEY setting must not be empty error after editing django auth pipeline

我为 Facebook 登录添加了 python-social-auth,在添加具有自定义 piplene 函数的文件后,我的项目停止工作。所有操作都因已知问题而失败:

ImproperlyConfigured: The SECRET_KEY setting must not be empty.

正如我从许多其他人那里看到的那样post,原因在于循环依赖,但我无法想象它在哪里。

这是 settings.py 的清单:

import os

from config import *
from FBAuth.facebook import *
....

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'FBAuth',
'social.apps.django_app.default',    
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
'social_auth.middleware.SocialAuthExceptionMiddleware',
)


AUTHENTICATION_BACKENDS = (
'social.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',                
            'django.contrib.messages.context_processors.messages',
            'social.apps.django_app.context_processors.backends',
            'social.apps.django_app.context_processors.login_redirect',                
        ],
    },
},
]


TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'social.apps.django_app.context_processors.backends',
            'social.apps.django_app.context_processors.login_redirect',   
            
        ],
    },
},
 ]

SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'
FIELDS_STORED_IN_SESSION = ['login_type']
LOGIN_ERROR_URL = '/login_error/'

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'FBLogin.facebook.check_if_exists',     
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)

注意:我删除了所有不相关的默认设置

facebook.py:

from django.shortcuts import  redirect
from django.contrib.auth.models import User
from social.exceptions import AuthCanceled    

def check_if_exists(*args, **kwargs):
    #request = kwargs.get('request')
     if kwargs['is_new']:
        if request.session['login_type'] == 'login': #need to add message
            raise AuthCanceled
    else: 
        if request.session['login_type'] == 'signup':  #need to add message
            raise AuthCanceled
    return None

我正在尝试找出阻塞问题所在。

尝试从您的 setting.py:

中删除这一不必要的行
from FBAuth.facebook import *