django auth:密码更改模板自定义
django auth: password change template customization
我想将 django auth 的密码更改模板主题化到我的站点。问题是 django 看到的是模板的 django/contrib/admin/templates/registration/
版本,而不是我精心制作的 myapp/template/registration/password*.html
.
This poster was told to fiddle with app order in settings.py, which is a bit fragile to my taste. I think this发帖人可能已经得到了合理的答案,但如果是这样,我还没有完全理解。
所以我所做的就是在我的 urls.py
文件中添加一堆非 DRY 垃圾,从 auth_urls.py
:
复制
# Provide explicit templates where I've provided them, shadowing the URL's
# that registration.backends.defaults.urls will provide.
url(r'^accounts/password/change/$',
auth_views.password_change,
{'post_change_redirect': reverse_lazy('auth_password_change_done'),
'template_name': 'registration/password/change_form.html' },
name='auth_password_change'),
# ...
url(r'^accounts/', include('registration.backends.default.urls')),
这行得通,但它的重复让我感到难过。当然,django 鼓励更清洁的东西。有什么指点吗?
(Fwiw,django 1.7 和 python 3.4.2。)
将此模板放入项目的 templates
目录并将以下代码添加到 settings.py
.
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
默认情况下,django.template.loaders.filesystem.Loader
位于 TEMPLATE_LOADERS
中的 django.template.loaders.app_directories.Loader
之前,因此项目的 templates
目录优先于应用程序的 templates
.
我想将 django auth 的密码更改模板主题化到我的站点。问题是 django 看到的是模板的 django/contrib/admin/templates/registration/
版本,而不是我精心制作的 myapp/template/registration/password*.html
.
This poster was told to fiddle with app order in settings.py, which is a bit fragile to my taste. I think this发帖人可能已经得到了合理的答案,但如果是这样,我还没有完全理解。
所以我所做的就是在我的 urls.py
文件中添加一堆非 DRY 垃圾,从 auth_urls.py
:
# Provide explicit templates where I've provided them, shadowing the URL's
# that registration.backends.defaults.urls will provide.
url(r'^accounts/password/change/$',
auth_views.password_change,
{'post_change_redirect': reverse_lazy('auth_password_change_done'),
'template_name': 'registration/password/change_form.html' },
name='auth_password_change'),
# ...
url(r'^accounts/', include('registration.backends.default.urls')),
这行得通,但它的重复让我感到难过。当然,django 鼓励更清洁的东西。有什么指点吗?
(Fwiw,django 1.7 和 python 3.4.2。)
将此模板放入项目的 templates
目录并将以下代码添加到 settings.py
.
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
默认情况下,django.template.loaders.filesystem.Loader
位于 TEMPLATE_LOADERS
中的 django.template.loaders.app_directories.Loader
之前,因此项目的 templates
目录优先于应用程序的 templates
.