身份验证视图无法识别HTML模板

时间:2019-08-24 13:38:56

标签: django django-views

我在项目https://docs.djangoproject.com/en/2.2/topics/auth/default/#module-django.contrib.auth.views中使用身份验证视图
path('accounts/', include('django.contrib.auth.urls')),在我的网址中
我的问题是,关于PasswordChangeViewaccounts/password_change网址显示的是django管理页面,而不是我在posts\templates\registration\password_change_form.html下拥有的模板 enter image description here

1 个答案:

答案 0 :(得分:1)

您是否在 urls.py 中设置了template_name

  

在我的项目中有效的示例。

from django.urls import path, reverse_lazy
from . import views
from django.contrib.auth import views as auth_views



app_name='account'

urlpatterns = [

<...>

    # -- Change Password
    path('change_password/', auth_views.PasswordChangeView.as_view(
        template_name='password/password_change.html',
        success_url=reverse_lazy('account:password_change_done')), 
        name='password_change'),

<...>
]

根据您的情况将其设置为template_name='registration\password_change_form.html'

相关问题