簡體   English   中英

django auth:密碼更改模板自定義

[英]django auth: password change template customization

我想將django auth的密碼更改模板設置為我的網站。 問題是django看到的是django/contrib/admin/templates/registration/模板版本,而不是精心制作的myapp/template/registration/password*.html

告訴這位海報的人在settings.py中擺弄應用程序順序,這對我來說有點脆弱。 我認為這張海報可能已經得到了一個合理的答案,但是如果是這樣,我還不太了解。

因此,我要做的是向從auth_urls.py復制的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'),
)

默認情況下,在TEMPLATE_LOADERSdjango.template.loaders.filesystem.Loader放在django.template.loaders.app_directories.Loader之前,因此項目的templates目錄優先於應用程序的templates

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM