python - 找不到 Facebook 后端

标签 python django facebook python-social-auth

伙计们,我似乎无法让它工作,在阅读了类似的问题后,我的问题不是因为没有指定 key 和 secret ,也不是因为我忘记在 facebook 之后添加“-oauth2”。 请帮忙??

我在浏览器上看到的只是未找到后端。也许只是因为我的 django 或 python 版本太新了?? 我使用 python 3.6 和 django 2.0...

这是我项目的settings.py

SECRET_KEY = '<my_secret_key>'

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


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_app',
    'django_filters',
    'cuentas',
    'social_django',
]

MIDDLEWARE = [
    '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',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]

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.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

# python social auth settings
SOCIAL_AUTH_FACEBOOK_KEY = '<facebook_app_id>'

SOCIAL_AUTH_FACEBOOK_SECRET = '<facebook_app_secret>'

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

SOCIAL_AUTH_FACEBOOK_API_VERSION = '2.11'

AUTHENTICATION_BACKENDS = [
    'social_core.backends.facebook.FacebookAppOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
]

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
    'social_core.pipeline.social_auth.associate_by_email',
)

更新...这是我的主要应用程序的 urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', include('social_django.urls', namespace='social')),
    path('admin/', admin.site.urls),
    path('', include('main_app.urls') ),
    path('cuentas/', include('cuentas.urls')),
]

if settings.DEBUG is True:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

这是使用 facebook html 链接登录

<a href="{% url 'social:begin' 'facebook-oauth2' %}">Facebook</a>

我刚刚在 settings.py 中添加了配置以输出更多日志信息,所以这是我尝试使用 facebook 登录时的输出

Performing system checks..
System check identified no issues (0 silenced).
January 12, 2018 - 11:23:23
Django version 2.0, using settings 'jaguamigos.settings'
Starting development server at http://127.0.0.1:80/
Quit the server with CTRL-BREAK.
Not Found: /favicon.ico
Not Found: /favicon.ico
Not Found: /login/facebook-oauth2/
Not Found: /login/facebook-oauth2/

最佳答案

omab绝对正确,为 facebook 后端插入 name 属性就成功了。

# Use 'facebook' instead of 'facebook-oauth2'
{% url 'social:begin' 'facebook' %}

关于python - 找不到 Facebook 后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48214134/

相关文章:

android - 如何将位于第三方应用程序或浏览器(如 whatsapp 消息)的 url 直接打开到我的 webview 应用程序中?

android - facebook分享权限申请审核android

python - connection.commit() 和cursor.execute ('commit' 之间有什么区别?

python - 如何忽略Rollbar中的404异常?

javascript - D3.js "exporting"数据

python - Twisted 和 pyapns 的推送通知错误

android - java.lang.RuntimeException : Unable to start activity ComponentInfo , android.content.res.Resources$NotFoundException 异常

python - 部署 Django : How do you do it?

python - 无效请求错误 : Object '' is already attached to session

python 位数组到文件和从文件