简体   繁体   中英

django auth: password change template customization

I want to theme django auth's password change templates to my site. The problem is that django is seeing the django/contrib/admin/templates/registration/ versions of the templates instead of my beautifully crafted 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 poster may have gotten a reasonable answer, but if so, I haven't quite understood it yet.

So what I did was to add a bunch of non-DRY cruft to my urls.py file, copied from 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')),

This works, but saddens me in its repetition. Surely django encourages something cleaner. Any pointers?

(Fwiw, django 1.7 and python 3.4.2.)

Put this template into your project's templates dir and add the following code to the settings.py .

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

By default django.template.loaders.filesystem.Loader is placed before django.template.loaders.app_directories.Loader in TEMPLATE_LOADERS so project's templates directory has precedence over app's templates .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM