python - django 1.6.5 密码重置电子邮件检查有效链接

标签 python django

我正在按照此 blog 中的确切步骤进行操作.

还进行了更改:

1) the url template tag syntax as noted above by "F L" 
2) uidb36 in the urls.py and email template both should be uidb64 per https://docs.djangoproject.com/en/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk

当我输入电子邮件地址时,我收到邮件,输入网址后:http://localhost:8000/user/password/reset/NDI-47h-e1fbd1df48ce2aa05de4/ ,我总是收到消息:

Password reset unsuccessful
The password reset link was invalid, 
possibly because it has already been used. 
Please request a new password reset.

即有效链接总是失败。为什么?

分享相关代码块:urls.py:

urlpatterns = patterns('',
                       url(r'^admin/', include(admin.site.urls)),
                       url(r'^user/password/reset/$', 
                           'django.contrib.auth.views.password_reset', 
                           {'post_reset_redirect' : '/user/password/reset/done/'}, name="password_reset"),
                       (r'^user/password/reset/done/$',
                        'django.contrib.auth.views.password_reset_done'),
                       (r'^user/password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)-(?P<token>.+)/$', 
                        'django.contrib.auth.views.password_reset_confirm', 
                        {'post_reset_redirect' : '/user/password/done/'}),
                       (r'^user/password/done/$', 
                        'django.contrib.auth.views.password_reset_complete'),

在我的模板文件夹中,创建了一个名为registration的文件夹:我的模板文件夹的结构: /模板$查找

.
./registration
./registration/password_reset_form.html
./registration/password_reset_confirm.html
./registration/password_reset_email.html
./registration/password_reset_done.html
./registration/password_reset_complete.html
./admin

password_reset_email.html:

{% load i18n %}
{% comment %}
{% load url from future %}
{% endcomment %}
{% autoescape off %}

You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.

Please go to the following page and choose a new password:
{% block reset_link %}
{{ 'http' }}://{{ 'localhost:8000' }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}
{% endblock %}

Your username, in case you've forgotten: {{ user.username }}

Thanks for using our site!

The {{ site_name }} team.

blog 中的所有其他模板

最佳答案

我猜您的网址中的 - 是一个问题,因为您的第一个正则表达式组与 - 贪婪地匹配。

请注意,- 与第一个正则表达式匹配,但您使用它作为分隔符。

而不是这个 URL 模式:

r'^user/password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)-(?P<token>.+)/$'

试试这个:

r'^user/password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$'

不同之处在于,我们将匹配组之间的 - 更改为 /,这是第一个组中不匹配的字符。

关于python - django 1.6.5 密码重置电子邮件检查有效链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34133305/

相关文章:

python - 在 Django 开发服务器上打开页面时出现错误状态行异常

python - 部署在pythonanywhere上的django项目链接静态文件出错

django - 基于列表显示中的自定义可调用项在 Django Admin 中进行排序

python - 为第三方创建 api token

python - 无法解析余数 : '==obj.id' from 'sobj.id==obj.id'

python - 求解多个参数的方程/表达式

python:将日期时间戳转换为纪元unix时间并计算剩余天数?

python - 关于python中数据类型的说明

python - 在 python 3 中导入 win32com 时遇到问题

Django Microsoft 身份验证后端在新部署中未成功