Django auth:密码更改模板自定义

2024-04-26 18:08:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把django auth的密码更改模板主题化到我的站点。问题是django看到的是模板的django/contrib/admin/templates/registration/版本,而不是我精心制作的myapp/template/registration/password*.html。在

This海报被告知在设置.py,这对我来说有点脆弱。我想this海报可能得到了一个合理的答案,但如果是这样的话,我还没有完全理解它。在

所以我做的就是在我的urls.py文件中添加一堆非干性垃圾,从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和python3.4.2。)


Tags: djangopyauth模板urlhtmltemplatepassword
1条回答
网友
1楼 · 发布于 2024-04-26 18:08:33

将此模板放入项目的templates目录,并将以下代码添加到settings.py。在

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

默认情况下,django.template.loaders.filesystem.Loader放在TEMPLATE_LOADERS中的django.template.loaders.app_directories.Loader之前,所以project的templates目录优先于app的templates。在

相关问题 更多 >