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/
我想在 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/