如何在Django中使用内置的“password_reset”视图? [英] How to use the built-in 'password_reset' view in Django?

查看:401
本文介绍了如何在Django中使用内置的“password_reset”视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在urls.py

I have set the following entry in the urls.py

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

但一旦我去 http://127.0.0.1:8000/password_reset/ 我收到错误信息:

but once I go to http://127.0.0.1:8000/password_reset/ I get the error message:

NoReverseMatch at /password_reset/
Reverse for 'django.contrib.auth.views.password_reset_done' with arguments '()' and keyword arguments '{}' not found.

我期待password_reset_done视图也是开箱即用的。那么在这个阶段我应该做什么?

I was expecting password_reset_done view also to be coming out of the box. So what am I supposed to do at this stage?

更新

之后尝试Blair的解决方案,我走得更近了。

After trying Blair's solution, I got a step closer.

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

根据本书Django 1.0网站开发,这些内置视图应该开箱即用,没有进一步的麻烦。但也许它已经改变自Django 1.0 ...
如果有人可以阐明这一点,将是伟大的。谢谢

According to the book 'Django 1.0 Website Development', these built-in views should be used out of the box without further hassle. But maybe it has changed since Django 1.0... Would be great if someone could shed light on this. Thanks

推荐答案

我终于找到了解决方案。我认为MVC和MTV模式之间总是有一些误区。在MTV(Django)中,视图代表控制器,模板代表视图。

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.

因此,尽管其更改密码Views正在内置开箱即用,实际的模板(外观和感觉)仍然需要由用户生成,而底层窗体(小部件)由Django自动生成。查看代码时会变得更加清晰。

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.

因此,将这两行添加到 url.py

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'),

然后在myproject /模板/注册添加这两个文件

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 
    <a href="/login/">login</a> or go back to the
    <a href="/">main page</a>.
{% endblock %}

password_change_form.html p>

password_change_form.html

{% extends "base.html" %}
{% block title %}Change Registration{% endblock %}
{% block head %}Change Registration{% endblock %}
{% block content %}
    <form method="post" action=".">
        {{form.as_p}}
        <input type="submit" value="Change" />
        {% csrf_token %}
    </form>
{% endblock %}

这篇关于如何在Django中使用内置的“password_reset”视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆