簡體   English   中英

django:密碼更改模板自定義

[英]django: password change template customization

我想在 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',
            ],
        },
    },
]

您可以在 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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM