问题描述
我想在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/