gpt4 book ai didi

python - 试图覆盖在 python 3.9 中识别的 Django 3.2 应用程序上的 allauth 模板

转载 作者:行者123 更新时间:2023-12-04 12:28:53 25 4
gpt4 key购买 nike

我在 Django 3.2 上与 ALLAUTH 合作。我找到的大多数解决方案都是针对 Django 1 的,所以我希望在这里找到更新的内容。
我已经安装了模块/应用程序,但是我在用我自己的模板覆盖模板时遇到了问题。
在 settings.py 中:

INSTALLED_APPS = [
...
'Landing.apps.LandingConfig',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google'
]

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR / 'templates'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Already defined Django-related contexts here

# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]

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',
]
研究网址 #该项目
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('', include('Landing.urls')),
path('admin/', admin.site.urls),
path('accounts/', include('allauth.urls')),
]
登陆/urls.py #应用级网址
from django.contrib import admin
from django.urls import path, include

from . import views

urlpatterns = [
path('', views.home, name='home'),
path('login/', views.LoginView.as_view(), name='account_login'),
path('signup/', views.SignupView.as_view(), name='account_signup')
]
首页.html
<...>
<body>
<H1>This is the homepage</H1>
<p><a href="{% url 'account_login' %}">login</a></p>
<p><a href="{% url 'account_signup' %}">Create Account</a></p>

</body>
<...>
注: account_loginaccount_signup都在登陆网址和登陆 View 中
登陆意见
from django.shortcuts import render
from allauth.account.views import LoginView, SignupView


# Create your views here.
def home(request):
return render(request, 'Landing/home.html')


class LandingLogin(LoginView):
print('found Login View....')
template_name = 'authentication/login.html'


class LandingSignup(SignupView):
print('found Login View....')
template_name = 'authentication/account_signup.html'

我的树
enter image description here
我可以导航到 localhost:8000,当 html 出现时,会发生两件事:
  • home.html 上的链接仍然指向 allauth 链接
  • Landing/Home 指向自定义模板,但它仍然路由到 allauth 页面。

  • 如何设置 View 、链接和路由到正确的页面?
    谢谢!

    最佳答案

    Landing/urls.py , loginsignup仍然指向 allauth View ( allauth.account.views.LoginViewallauth.account.views.SignupView )而不是被覆盖的 View 。
    您可以尝试从以下位置更改它们:

        path('login/', views.LoginView.as_view(), name='account_login'),
    path('signup/', views.SignupView.as_view(), name='account_signup')
    到:
        path('login/', views.LandingLogin.as_view(), name='account_login'),
    path('signup/', views.LandingSignup.as_view(), name='account_signup')

    关于python - 试图覆盖在 python 3.9 中识别的 Django 3.2 应用程序上的 allauth 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68311113/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com