尝试使用fb js_sdk登录时,我收到以下错误。但是当我切换回使用它时,使用oauth2工作正常。我在某个地方错过了一些配置吗?
Internal Server Error: /accounts/facebook/login/token/
NoReverseMatch at /accounts/facebook/login/token/
Reverse for '' with arguments '()' and keyword arguments '{'request': <WSGIRequest: POST '/accounts/facebook/login/token/'>}' not found. 0 pattern(s) tried:
settings.py
INSTALLED_APPS = [
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'debug_toolbar',
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'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',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ BASE_DIR + '/main/templates/allauth/',],
'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',
'main.context_processors.get_search_query'
],
},
},
]
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
# ALLAUTH
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "optional"
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_SIGNUP_FORM_CLASS = 'main.forms.SignupForm'
ACCOUNT_PRESERVE_USERNAME_CASING = True
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = True
ACCOUNT_SESSION_REMEMBER = True
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'METHOD': 'js_sdk',
'SCOPE': ['email', 'public_profile'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'FIELDS': [
'id',
'email',
'name',
'first_name',
'last_name',
'verified',
'locale',
'timezone',
'link',
'gender',
'updated_time',
],
'EXCHANGE_TOKEN': True,
'VERIFIED_EMAIL': False,
'VERSION': 'v2.4',
}
}
的login.html
{% extends "bases/bootstrap-auth.html" %}
{% load static %}
{% load i18n %}
{% load bootstrap3 %}
{% load account socialaccount %}
{% block head %}<meta name="robots" content="noindex">{% endblock %}
{% block extra_title %}{% trans "Log In" %}{% endblock %}
{% block inner-content %}
{% providers_media_js %}
{% get_providers as socialaccount_providers %}
<div class="text-center">
<h1 class="text-center">Log In</h1>
<small>Don't have an account? <a href="{% url 'account_signup' %}">Signup, it's free!</a></small>
</div><hr>
<div class="row">
<div class="col-md-6 col-lg-6 col-md-offset-3">
<a title="{{provider.name}}" href="{% provider_login_url "facebook" method="js_sdk" %}"
class="btn btn-block btn-social btn-facebook">
<span class="fa fa-facebook"></span> Login with Facebook
</a>
<div class="strike">
<span>or</span>
</div>
</div>
</div>
{% endblock %}
{% block head_css %}
<link rel="stylesheet" href="{% static 'css/bootstrap-social.css' %}" rel="stylesheet">
{% endblock %}
urls.py
urlpatterns = [
url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/profile/$', main.views.account_profile, name='account_profile'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
答案 0 :(得分:0)
您是否已将correct code添加到urls.py
?
urlpatterns = [
...
url(r'^accounts/', include('allauth.urls')),
...
]
答案 1 :(得分:0)
请确保您在settings.py文件中具有正确的登录重定向URL设置 LOGIN_REDIRECT_URL =“ /”