Django 1.0,使用默认密码重置

时间:2022-04-27 20:29:51

I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error:

我正在尝试使用Django附带的密码重置设置,但文档不是很好。我正在使用Django 1.0,我不断收到此错误:

Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments ...

in my urlconf I have something like this:

在我的urlconf中,我有这样的事情:

#django.contrib.auth.views
urlpatterns = patterns('django.contrib.auth.views',    
    (r'^password_reset/$', 'password_reset', {'template_name': 'accounts/registration/password_reset_form.html', 'email_template_name':'accounts/registration/password_reset_email.html', 'post_reset_redirect':'accounts/login/'}),
    (r'^password_reset/done/$', 'password_reset_done', {'template_name': 'accounts/registration/password_reset_done.html'}),
    (r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'password_reset_confirm', {'template_name': 'accounts/registration/password_reset_confirm.html', 'post_reset_redirect':'accounts/login/', 'post_reset_redirect':'accounts/reset/done/'}),
    (r'^reset/done/$', 'password_reset_complete', {'template_name': 'accounts/registration/password_reset_complete.html'}),
)

The problem seems to be in this file:

问题似乎出现在这个文件中:

password_reset_email.html 

on line 7

在第7行

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

I'm at loss as to what's going on, so any help would be appreciated.

我不知道发生了什么,所以任何帮助都会受到赞赏。

Thanks

4 个解决方案

#1


3  

Edit: I used your example, and had to change to not use keyword parameters.

编辑:我使用了您的示例,并且必须更改为不使用关键字参数。

{% url django.contrib.auth.views.password_reset_confirm uid, token %}

Named parameters do work, as long as both uid and token are defined. If either are not defined or blank I get the same error you do:

只要定义了uid和token,命名参数就可以工作。如果未定义任何一个或空白,我会得到同样的错误:

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

#2


2  

Just wanted to post the solution I came up with. The problem was in this line:

只想发布我想出的解决方案。问题出在这一行:

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

I'm not really a 100% why either, so I just hard coded the url like this:

我不是真的100%为什么,所以我只是硬编码这样的网址:

http://mysite.com/accounts/reset/{{uid}}-{{token}}/

#3


2  

I've struggled with this for over an hour trying everything on this page and every other page on the internet. Finally to solve the problem in my case i had to delete

我花了一个多小时在这个页面和互联网上的其他页面上尝试所有内容。最后解决我的问题,我不得不删除

{% load url from future %}

from the top of my password_reset_email.html template.

从我的password_reset_email.html模板的顶部。

Also note, "uidb36=uid" in the url script. Here's my full password_reset_email.html template, I hope it saves someone some time:

另请注意,url脚本中的“uidb36 = uid”。这是我的完整password_reset_email.html模板,我希望能节省一些时间:

{% 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 %}
{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid token=token %}
{% endblock %}

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

Thanks for using our site!

The {{ site_name }} team

{% endautoescape %}

#4


0  

This is a problem I figured out myself not 10 minutes ago. The solution is to add the post_change_redirect value to the dictionary of arguments you are passing to the password_reset view.

这是我在10分钟前发现自己的问题。解决方案是将post_change_redirect值添加到要传递给password_reset视图的参数字典中。

So this is what mine now look like:

所以这就是我现在的样子:

(r'^/password/$', password_change, {'template_name': 'testing/password.html', 'post_change_redirect': '/account/'})

I hope that does it for you! I agree that the documentation for this particular feature is lacking somewhat, but this solved the exact same issue for my project.

我希望能帮到你!我同意这个特定功能的文档缺乏一些,但这解决了我的项目完全相同的问题。

Edit: I really should have scrolled across - you've included that already. Apologies for that, but I hope you get it sorted :)

编辑:我真的应该滚动 - 你已经包括了。为此道歉,但我希望你把它排序:)

#1


3  

Edit: I used your example, and had to change to not use keyword parameters.

编辑:我使用了您的示例,并且必须更改为不使用关键字参数。

{% url django.contrib.auth.views.password_reset_confirm uid, token %}

Named parameters do work, as long as both uid and token are defined. If either are not defined or blank I get the same error you do:

只要定义了uid和token,命名参数就可以工作。如果未定义任何一个或空白,我会得到同样的错误:

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

#2


2  

Just wanted to post the solution I came up with. The problem was in this line:

只想发布我想出的解决方案。问题出在这一行:

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

I'm not really a 100% why either, so I just hard coded the url like this:

我不是真的100%为什么,所以我只是硬编码这样的网址:

http://mysite.com/accounts/reset/{{uid}}-{{token}}/

#3


2  

I've struggled with this for over an hour trying everything on this page and every other page on the internet. Finally to solve the problem in my case i had to delete

我花了一个多小时在这个页面和互联网上的其他页面上尝试所有内容。最后解决我的问题,我不得不删除

{% load url from future %}

from the top of my password_reset_email.html template.

从我的password_reset_email.html模板的顶部。

Also note, "uidb36=uid" in the url script. Here's my full password_reset_email.html template, I hope it saves someone some time:

另请注意,url脚本中的“uidb36 = uid”。这是我的完整password_reset_email.html模板,我希望能节省一些时间:

{% 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 %}
{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid token=token %}
{% endblock %}

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

Thanks for using our site!

The {{ site_name }} team

{% endautoescape %}

#4


0  

This is a problem I figured out myself not 10 minutes ago. The solution is to add the post_change_redirect value to the dictionary of arguments you are passing to the password_reset view.

这是我在10分钟前发现自己的问题。解决方案是将post_change_redirect值添加到要传递给password_reset视图的参数字典中。

So this is what mine now look like:

所以这就是我现在的样子:

(r'^/password/$', password_change, {'template_name': 'testing/password.html', 'post_change_redirect': '/account/'})

I hope that does it for you! I agree that the documentation for this particular feature is lacking somewhat, but this solved the exact same issue for my project.

我希望能帮到你!我同意这个特定功能的文档缺乏一些,但这解决了我的项目完全相同的问题。

Edit: I really should have scrolled across - you've included that already. Apologies for that, but I hope you get it sorted :)

编辑:我真的应该滚动 - 你已经包括了。为此道歉,但我希望你把它排序:)