Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

django - NoReverseMatch on password_Reset_confirm

I have a problem getting password_Reset_confirm bit working.

url:

(r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
(r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'),
(r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),

password_reset_email.html, which includes this:

{% load url from future %}
Someone asked for password reset for email {{ email }}. Follow the link below:
{{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb36=uid token=token %}

But then after submitting my email for reseting the password, I get this error message shown:

NoReverseMatch at /password_reset/ Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{'uidb36': '1', 'token': '38d-b5ec0b2a2321f522f954'}' not found.

I thought since this was using a build in view, I wouldn't have to take care on anything else?

Thanks for advice,

Update:

After using the full path, it seems to work. However it sends two emails out: and each has a different link. Why is that? And where do I set the {{ domain }}? Thanks

Follow the link below:
http://example.com/password_reset_confirm/1-38d-b5ec0b2a2321f522f954/

Follow the link below:
http://example.com/password_reset_confirm/2-38d-18482e1f129c84b9c2bc/

Update 2

I figured it out. Just in case someone else has this problem. You need to set your domain name as the Site for your application:

In Admin or django console:

>>> my_site = Site.objects.get(pk=1)
>>> my_site.domain = 'somedomain.com'
>>> my_site.name = 'Some Domain'
>>> my_site.save()

The other problem why you could get two emails when resetting it, is because that you can have multiple usernames associated with the same email address. Its pretty silly. This is the next thing I have to tackle down.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To pass a url to the url template tag, you can specify a name to the url in the urls.py

url(r'^reset/(?P<uidb64>[0-9A-Za-z_-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 
views.password_reset_confirm, name='password_reset_confirm'),

and then you can use the tag with the url name

{% url 'password_reset_confirm' uidb64=uid token=token %}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...