gpt4 book ai didi

python - Django Social Wrong后端错误

转载 作者:行者123 更新时间:2023-11-30 23:32:48 25 4
gpt4 key购买 nike

我对 django 还很陌生,对 django-social-auth 完全是菜鸟。我的settings.py代码是这样的(从安装的应用程序到social_auth_config):

DJANGO_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
)

THIED_PARTY_APPS = (
#'south',
'captcha',
'social_auth',
)

MY_APPS = (
'account',
'dashboard',
)

INSTALLED_APPS = DJANGO_APPS + THIED_PARTY_APPS + MY_APPS
#------------------------------------------------- Social auth -------------------
LOGIN_URL = 'account/login/'
LOGIN_REDIRECT_URL = 'dashboard/'
LOGIN_ERROR_URL = '/login/'

AUTHENTICATION_BACKENDS = (
'social_auth.backends.contrib.github.GithubBackend',
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"social_auth.context_processors.social_auth_by_type_backends",
"django.contrib.auth.context_processors.auth",
)
SOCIAL_AUTH_DEFAULT_USERNAME = 'nal_auth_user'
SOCIAL_AUTH_UID_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_ENABLED_BACKENDS = ('github',)
GITHUB_API_KEY = '2f1129e79efd4263bf88'
GITHUB_API_SECRET = '6f4cea73e6100d0a994fa5bfff44f7220432c87d'

在 urls.py 中:

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', 'website.views.index', name='index'),
url(r'auth/',include('social_auth.urls')),
url(r'account/',include('account.urls',namespace="account")),
url(r'dashboard/',include('dashboard.urls',namespace="dashboard")),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)

在 account.models 登录页面中,我有这个来显示登录网址..

<a href="{% url 'socialauth_begin' 'github' %}">Login with GitHub</a>

但问题是,当我点击该链接时,它会给我这个错误

WrongBackend at /auth/login/github/
Incorrect authentication service "github"
Request Method: GET
Request URL: http://127.0.0.1:8000/auth/login/github/
Django Version: 1.5.4
Exception Type: WrongBackend
Exception Value:
Incorrect authentication service "github"

我尝试使用谷歌,它给了我同样的错误,除了 github 中的谷歌。我也在 stackoverflow 中尝试过类似的问题。

如果可以的话请帮助我:)

最佳答案

  1. 查看django_sociao_auth的库版本,因为“此库已弃用,转而使用 python-social-auth。现在此库直接依赖于 python-social-auth,应将其视为迁移步骤”。另请检查 SETTINGS_KEY_NAME = 'GITHUB_APP_ID' SETTINGS_SECRET_NAME = 'GITHUB_API_SECRET' 是否属于 GithubAuth

  2. 然后尝试添加此内容

    SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.misc.save_status_to_session',
    'social_auth.backends.pipeline.user.create_user',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details',
    'social_auth.backends.pipeline.misc.save_status_to_session',
    )

关于python - Django Social Wrong后端错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19215545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com