简体   繁体   中英

django: password change template customization

I want to change password change template in django but I cant. django is seeing the django/contrib/admin/templates/registration/ versions of the templates instead of my beautifully crafted 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',
            ],
        },
    },
]

You can pass the template name in the auth view:

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'),

]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM