Django reset_password_confirm TemplateSyntaxError问题

Afi*_*iku 17 django django-templates

当我使用django.contrib.auth.views.password_reset_confirm而没有参数时它可以工作,我可以毫无问题地渲染模板,当添加uidb36和令牌参数时它失败了.

渲染时捕获NoReverseMatch:反向'django.contrib.auth.views.password_reset_confirm',参数'()'和关键字参数'{'uidb36':'111','token':'1111111111111'}'未找到.

Chr*_*rry 24

最有可能的是你的urls.py问题.您需要设置正确的模式以获取作为URL参数传递的uidb36和标记值.如果没有,它将抛出与您上面看到的类似的错误.

就像是:

(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', {'template_name' : 'registration/password_reset.html',  'post_reset_redirect': '/logout/' })
Run Code Online (Sandbox Code Playgroud)

registration/password_reset.html - 是我的自定义模板

注销 - 是我的自定义注销操作


gre*_*reg 6

我在Django 1.3中遇到过这个问题,浪费了很多时间,因为错误可以掩盖许多潜在的问题.

我需要将其添加到重置电子邮件模板的顶部:

{% load url from future %}
Run Code Online (Sandbox Code Playgroud)

此外,Django文档中的示例与示例网址不匹配:

{{ protocol}}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}
Run Code Online (Sandbox Code Playgroud)

所以我不得不改变auth_password_reset_confirm上面的内容password_reset_confirm.


Lun*_*ata 6

如果您正在使用Django 1.6+并遇到类似这样的问题,那么您可能需要在模板和网址中将uidb36更新为uidb64.

示例网址: url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', auth_views.password_reset_confirm

并重置模板中的链接:

{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}