我想将 django auth 的密码更改模板主题设置到我的网站。问题是 django 看到的是 django/contrib/admin/templates/registration/
版本的模板,而不是我精心制作的 myapp/template/registration/password*.html
>.
This海报被告知要在settings.py中摆弄应用程序顺序,这对我来说有点脆弱。我认为this发帖人可能已经得到了合理的答案,但如果是这样,我还不太明白。
所以我所做的就是向我的 urls.py
文件添加一堆非 DRY cruft,该文件是从 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
。
关于python - Django 身份验证 : password change template customization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28010276/