向 django admin 添加社交应用程序时没有项目提供者下拉菜单

问题描述 投票:0回答:1

Django 管理面板我目前正在学习使用 django 进行 Web 开发,在尝试使用 django-allauth 将社交身份验证添加到我的项目时,我遇到了一个错误,在加载社交帐户标签并创建与提供商登录 url 标签,我认为这是因为我还没有将社交应用程序添加到 django 管理中,所以我尝试了这一点,我去了网站并添加了 127.0.0.1:8000 作为我的链接,其中 google 作为名称,但是当我尝试添加社交应用程序,下拉菜单中没有项目,我通常应该选择提供商,即使我添加了 google、faceboook 和 microsoft 的 allauth.socialaccount.providers

我的设置.py-->

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites', 
    #Third-Party
    'allauth',
    'allauth.account',
    "allauth.socialaccount",
    "allauth.socialaccount.providers.google",
    'allauth.socialaccount.providers.microsoft',
    'allauth.socialaccount.providers.facebook',
    
]
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'EMAIL_AUTHENTICATION': True,
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        },
        'OAUTH_PKCE_ENABLED': True,
    }
}
LOGIN_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_REDIRECT = 'home'

#allauth config
SITE_ID = 1

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_USERNAME_REQUIRED = False 
ACCOUNT_AUTHENTICATION_METHOD = 'email' 
ACCOUNT_EMAIL_REQUIRED = True 
ACCOUNT_UNIQUE_EMAIL = True 
ACCOUNT_EMAIL_VERIFICATION = "none"

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

urls.py -->


urlpatterns = [
    #admin
    path('admin/', admin.site.urls),
    
    #User management
    path('accounts/', include('allauth.urls')),
    path('accounts/', include('allauth.socialaccount.urls')),
]

login.html -->

{% extends 'base.html' %}
{% load account %}
{% load static %}
{% block title %}Log In{% endblock title %}

{% block content %}
<div class="wrapper">
    <div>
        <img class="auth-image" src="{% static "images/AuthImg.jpg" %}">
    </div>
    <div id="auth-form-box">
        <div id="log-in">
            <h2>Log In</h2>
        </div>
        <div id="form-field">
            <form class='form' method="post">
                {% csrf_token %}
                <div class="field">
                    <h1>Email address</h1>
                    <div class='input'>
                        {{ form.login }}
                    </div>
                </div>
                <div class="field">
                    <h1>Password</h1>
                    <div class='input'>
                        {{ form.password }}
                    </div>
                </div>
                <div class="remember-tick">
                    {{ form.remember }}
                    <label for="remember" class="">remember me</label>
                </div>
                <button class="btn-submit" type="submit">Log In</button>
            </form>
            {% load socialaccount %}
            <a href="{% provider_login_url 'google' %}">Sign up with Google</a>
        </div>
        <h1 class="dont-have">Don't have an account? sign in <a href="{% url "account_signup" %}">here</a></h1>
    </div>
</div>

我尝试将客户端 ID 和密钥添加到代码库本身,但这仍然没有解决问题,并且我仍然收到错误无效配置错误未知提供商“google”在以下期间引发:allauth.account.views.LoginView

django oauth-2.0 oauth django-templates google-oauth
1个回答
0
投票

我也有类似的问题。我将 allauth 降级到 0.61.1,“Google”现在出现在菜单中。

pip install django-allauth==0.61.1

我注意到,在 0.63.2 版本中,如果我通过将“allauth.socialaccount.providers.github”添加到 INSTALLED_APPS 来使用 Github 作为提供程序,那么 “Github”出现在菜单中,所以我认为这个问题专门与 Google 提供商有关。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.