gpt4 book ai didi

python - django 密码重置 password_reset_confirm

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:09 28 4
gpt4 key购买 nike

我正在用 django 做一个项目。在我的项目中,我需要通过电子邮件重置密码。为此,我使用了 django.contrib.auth.urls。当通过 djangos 模板时,我的测试成功了。后来我在我的模板上尝试了它,为此我创建了一个注册文件夹并创建了五个 html 页面,包括电子邮件模板。我还包括 url(r'^web/',include('django.contrib.auth.urls')),在我的主 url 中。但是当我运行服务器时,我可以将链接传递给电子邮件。并在我的浏览器中打开 View 。因为我更改了输入两次的密码,当我提交时没有任何反应发生了什么问题请帮助我?

我的password_reset_confirm.html是

{% extends 'base.html' %}
{% load i18n %}

{% block content %}
{% if validlink %}
<p>Please enter your new password twice.<br />
So we can verify you typed it in correctly.</p>
<form action="" method="post">
<div style="display:none">
<input type="hidden" value="{{ csrf_token }}"name="csrfmiddlewaretoken">
</div>
<table>
<tr>
<td>{{ form.new_password1.errors }}
<label for="id_new_password1">New password:</label></td>
<td>{{ form.new_password1 }}</td>
</tr>
<tr>
<td>{{ form.new_password2.errors }}
<label for="id_new_password2">Confirm password:</label></td>
<td>{{ form.new_password2 }}</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Change my password" /></td>
</tr>
</table>
</form>
{% else %}
<h1>Password reset unsuccessful</h1>
<p>The password reset link was invalid, <br />
possibly because it has already been used. <br />
Please request a new password reset.</p>
{% endif %}
{% endblock %}

最佳答案

我用有点不同的方式实现了密码重置程序,波纹管已经过测试并且有效:

在项目 urls.py 中:

urlpatterns = patterns('',
url(r'^user/', include('users.urls')),
)

在 urls.py 中:

...
url(r'^password-reset/$', 'django.contrib.auth.views.password_reset', kwargs={'template_name': 'password_reset_form.html'}, name='password-reset'),
url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done', kwargs={'template_name': 'password_reset_done.html'}, name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$','django.contrib.auth.views.password_reset_confirm',kwargs={'template_name': 'password_reset_confirm.html'},name='password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', kwargs={'template_name': 'password_reset_complete.html'}, name='password_reset_complete'),
...

为了方便起见,我在应用程序的根目录下创建了模板文件,上面的 url 在我项目的/user 下。

users/templates$ ls password*
password_reset_complete.html password_reset_done.html
password_reset_confirm.html password_reset_form.html

我测试了它的工作原理,表单与 django 提供的表单相同,只是我扩展了我的 frontpage 基本模板,因为我不希望前端用户看到任何 django 管理模板,例如:

{% extends "base.html" %}
{% load i18n %}

{% block title %}{% trans 'Password reset' %}{% endblock %}

{% block maincontent %}
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
{% if validlink %}
<h1>{% trans 'Enter new password' %}</h1>
<p>{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}</p>

<form action="" method="post">{% csrf_token %}
{{ form.new_password1.errors }}
<div class="form-group">
<label for="id_new_password1">{% trans 'New password:' %}</label>
<input class="form-control" type="password" id="id_new_password1" name="new_password1" value="">
</p>
{{ form.new_password2.errors }}
<div class="form-group">
<label for="id_new_password2">{% trans 'Confirm password:' %}</label>
<input class="form-control" type="password" id="id_new_password2" name="new_password2" value="">
</div>
<div class="row">
<div class="col-lg-l2">
<input type="submit" class="btn btn-default" value="{% trans 'Change my password' %}" />
</div>
</div>
</form>

{% else %}

<h1>{% trans 'Password reset unsuccessful' %}</h1>

<p>{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}</p>

{% endif %}
</div>
</div>
{% endblock maincontent %}

关于python - django 密码重置 password_reset_confirm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21284672/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com