【问题标题】:django: password change template customizationdjango:密码更改模板定制
【发布时间】:2020-09-12 14:21:35
【问题描述】:

我想在 django 中更改密码更改模板,但我不能。 django 看到模板的 django/contrib/admin/templates/registration/ 版本,而不是我精心制作的 myapp/templates/registration/password*.html

urls.py 

from django.contrib.auth.views import PasswordChangeDoneView,PasswordChangeView

urlpatterns = [
    path('password_change/',
         PasswordChangeView.as_view(),
         name='password_change'),
    path('password_change/done/',
         PasswordChangeDoneView.as_view(),
         name='password_change_done'),

]
setting.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

【问题讨论】:

    标签: python django templates change-password


    【解决方案1】:

    您可以在 auth 视图中传递模板名称:

    from django.contrib.auth.views import PasswordChangeDoneView,PasswordChangeView
    
    urlpatterns = [
        path('password_change/',
             PasswordChangeView.as_view(template_name="myapp/templates/registration/templatename.html"),
             name='password_change'),
        path('password_change/done/',
             PasswordChangeDoneView.as_view(template_name="myapp/templates/registration/templatename.html"),
             name='password_change_done'),
    
    ]
    

    来源:https://ccbv.co.uk/projects/Django/3.0/django.contrib.auth.views/PasswordChangeView/

    【讨论】:

      猜你喜欢
      • 2015-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2020-10-15
      • 1970-01-01
      相关资源
      最近更新 更多