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

前端 未结 3 1382
别跟我提以往
别跟我提以往 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:40

    I have finally found the solution. I think there is always the slight misunderstanding between MVC and MTV pattern. In MTV (Django) the View stands for the controller and the Template stands for the View.

    Hence while its true that the change password "Views" are coming built-in out-of-the-box, the actual templates (look & feel) still needs to be generated by the user while the underlying form (widget) is generated by Django automatically. It gets more clear when looking at the code.

    Therefore add these two lines to url.py

    (r'^change-password/$', 'django.contrib.auth.views.password_change'), 
    (r'^password-changed/$', 'django.contrib.auth.views.password_change_done'),
    

    Then Under myproject/templates/registration add these two files

    password_change_done.html

    {% extends "base.html" %}
    {% block title %}Password Change Successful{% endblock %}
    {% block head %}Password Change Completed Successfully{% endblock %}
    {% block content %}
        Your password has been changed successfully. Please re-login with your new credentials 
        login or go back to the
        main page.
    {% endblock %}
    

    password_change_form.html

    {% extends "base.html" %}
    {% block title %}Change Registration{% endblock %}
    {% block head %}Change Registration{% endblock %}
    {% block content %}
        
    {{form.as_p}} {% csrf_token %}
    {% endblock %}

    enter image description here

提交回复
热议问题