1

我对 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中尝试过类似的问题。

如果可以,请你帮助我 :)

4

1 回答 1

3
  1. check the version of the library of django_sociao_auth, as "THIS LIBRARY IS DEPRECATED IN FAVOR OF python-social-auth. RIGHT NOW THIS LIBRARY DEPENDS DIRECTLY ON python-social-auth AND SHOULD BE CONSIDERED AS A MIGRATION STEP". Also check if SETTINGS_KEY_NAME = 'GITHUB_APP_ID' SETTINGS_SECRET_NAME = 'GITHUB_API_SECRET' are in class GithubAuth

  2. then try to add this

    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',
    )
    
于 2013-10-07T02:29:46.367 回答