我没有代码问题,但有一点审美问题,我正在尝试使用 Django 简单登录一个应用程序,并能够使用 Google 输入,当我输入标签时,我希望它能够引导用户直接访问 Google,就像通常一样,但标签将它们发送到中间 Allaut 界面,然后按另一个按钮并继续,我想跳过该界面,但我已经尝试过,它总是引导我到那里
项目网址:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include("allauth.urls")),
path('', include("pagina.urls"))
]
应用程序网址:
from django.urls import path
from . import views
urlpatterns = [
path("", views.home),
path("logout", views.logout_view)
]
按钮的代码:
{% load socialaccount %}
<h1>Google Login</h1>
<a href="{% provider_login_url 'google' %}?next=/">Login with Google</a>
您称为“中间 allauth 接口”并使用 GET 请求调用的页面,仅提供一个使用 POST 请求继续登录的按钮。
你可以
更改初始页面上的按钮以直接发起 POST 请求,而不是 GET 登录网址或
设置 SOCIALACCOUNT_LOGIN_ON_GET=True(但不推荐)
参见下文 https://django-allauth.readthedocs.io/en/latest/configuration.html:
SOCIALACCOUNT_LOGIN_ON_GET(=假) 控制用于启动社交登录的端点(例如“/accounts/google/login/”)是否需要 POST 请求来启动握手。出于安全考虑,强烈建议需要POST请求。
还有另外两个背景类似的设置: ACCOUNT_CONFIRM_EMAIL_ON_GET ACCOUNT_LOGOUT_ON_GET
它工作得很好,对我来说,我只是添加了一个表单来发出 post 方法请求,因此它会跳过并直接带我进入 Google 登录
<form action="{% provider_login_url 'google' method='POST' %}" method="post">
{% csrf_token %}
<button type="submit" class="btn btn-primary btn-sm ms-2">Conectar con Google</button>
</form>