如果你在每个 urls.py 中都使用 app_name
假设您有一个应用程序,并且在该应用程序的 urls.py 中您提到了 app_name="accounts"
为了检索页面,您需要提及两件事
PasswordResetView 中的 template_name 和 success_url(template_name="accounts/password_reset.html" , success_url= reverse_lazy('accounts:password_reset_sent'))
不要忘记从 urls.py 中的 django.urls 导入 reverse_lazy
所以您的帐户/urls.py 的最终代码应该是这样的
我的应用名称是登陆而不是帐户
from django.urls import path
from . import views
from django.contrib.auth import views as auth_views
from django.urls import reverse_lazy
app_name='landing'
urlpatterns = [
path('',views.home,name="home"),
path('terms/',views.terms,name="terms"),
path('login/',views.loginUser,name="login"),
path('signup/',views.signupUser,name="signup"),
path('about/',views.about,name="about"),
path('logout/',views.logoutUser,name="logout"),
path('password_reset/',
auth_views.PasswordResetView.as_view(template_name='landing/password_reset.html',success_url=reverse_lazy('landing:password_reset_done')),
name="password_reset"),
path('password_reset_sent/',
auth_views.PasswordResetDoneView.as_view(template_name='landing/password_reset_sent.html'),
name="password_reset_done"),
path('reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(template_name='landing/password_reset_form.html',success_url=reverse_lazy('landing:password_reset_complete')),
name="password_reset_confirm"),
path('password_reset_complete/',
auth_views.PasswordResetCompleteView.as_view(template_name='landing/password_reset_done.html'),
name="password_reset_complete"),
]
你必须在你提到的url名称之前使用app_name:,这很重要