How do I use the built in password reset/change views with my own templates

后端 未结 7 424
甜味超标
甜味超标 2020-11-29 16:08

For example I can point the url \'^/accounts/password/reset/$\' to django.contrib.auth.views.password_reset with my template filename in the contex

7条回答
  •  醉话见心
    2020-11-29 16:31

    You can do the following:

    1. add to your urlpatterns (r'^/accounts/password/reset/$', password_reset)
    2. put your template in '/templates/registration/password_reset_form.html'
    3. make your app come before 'django.contrib.auth' in INSTALLED_APPS

    Explanation:

    When the templates are loaded, they are searched in your INSTALLED_APPS variable in settings.py . The order is dictated by the definition's rank in INSTALLED_APPS, so since your app come before 'django.contrib.auth' your template were loaded (reference: https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.app_directories.Loader).

    Motivation of approach:

    1. I want be more dry and don't repeat for any view(defined by django) the template name (they are already defined in django)
    2. I want a smallest url.py

提交回复
热议问题