How to use the built-in 'password_reset' view in Django?

前端 未结 3 1418
别跟我提以往
别跟我提以往 2021-01-02 15:33

I have set the following entry in the urls.py

(r\'^password_reset/$\', \'django.contrib.auth.views.password_reset\'),

but once I go to

3条回答
  •  一向
    一向 (楼主)
    2021-01-02 15:41

    As of django 1.11 password_change view is deprecated.

    Deprecated since version 1.11: The password_change function-based view should be replaced by the class-based PasswordChangeView.

    What worked for me was:

    In urls.py

    from django.contrib.auth import views as auth_views
    ...
    url('^account/change-password/$',
        auth_views.PasswordChangeView.as_view(
            template_name='registration/passwd_change_form.html'),
        name='password_change'),
    url(r'^account/password-change-done/$',
        auth_views.PasswordChangeDoneView.as_view(
            template_name='registration/passwd_change_done.html'),
        name='password_change_done'),
    

    And then add the couple of templates passwd_change_form.html and passwd_change_done.html under registration.

    Note that I'm not using the default name, for some reason when I did that it defaulted to the django admin views.

提交回复
热议问题