【问题标题】:Authentication view doesn't recognize html template身份验证视图无法识别 html 模板
【发布时间】:2019-08-24 13:38:56
【问题描述】:

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

【问题讨论】:

    标签: django django-views


    【解决方案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'

    【讨论】:

    • 这行得通,但没有解决主要问题
    • @Saadat Esmaeily 您应该提供更多信息。据我了解,您的问题是:如何将您自己的模板用于password_change 而不是默认模板。
    猜你喜欢
    • 2014-08-31
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 2014-02-10
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多