Password reset email error


#1

I am a beginner learning of Python.

In reset password with email function, I got the error below. Please suggest.

NoReverseMatch at /accounts/password/reset/
Reverse for ‘django.contrib.auth.views.password_reset_confirm’ with arguments ‘()’ and keyword arguments ‘{u’uidb64’: ‘Mg’, u’token’: u’4h7-0436356a687253dab358’}’ not found. 0 pattern(s) tried: []


#2

Do you have the right import statement in your urls.py?


#3

I am using the same as book.

from django.contrib.auth.views import (
    password_reset, password_reset_done, 
    password_reset_confirm, 
    password_reset_complete,
)
from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import TemplateView
from collection import views


urlpatterns = [
    url(r'^$', views.index, name='home'),
    url(r'^about/$', TemplateView.as_view(template_name='about.html'), name='about'),
    url(r'^contact/$', TemplateView.as_view(template_name='contact.html'), name='contact'),
    url(r'^thing/(?P<slug>[-\w]+)/$', views.thing_detail, name='thing_detail'),
    url(r'^things/(?P<slug>[-\w]+)/edit/$', views.edit_thing, name='edit_thing'),
    url(r'^accounts/password/reset/$', password_reset, {'template_name': 'registration/password_reset_form.html'}, name="password_reset"),
    url(r'^accounts/password/reset/done/$', password_reset_done, {'template_name': 'registration/password_reset_done.html'}, name="password_reset_done"), 
    url(r'^accounts/password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, {'template_name':'registration/password_reset_confirm.html'}, name="password_reset_confirm"),
    url(r'^accounts/password/done/$', password_reset_complete, {'template_name': 'registration/password_reset_complete.html'}, name="password_reset_complete"),
    url(r'^account/', include('registration.backends.simple.urls')),
    url(r'^admin/', admin.site.urls),
]

#4

The code import here can be a bit wonky — can you make sure it is all on one line or has the right indentation?

Unfortunately, the way the print layout worked, I couldn’t put the code in the book on one line so that might have caused an issue if you were copy/pasting.


#5

Still error the same as above T.T.


#6

Here my code.

login.html

{% extends 'base.html' %}
{% block title %}
    Login - {{ block.super }}
{% endblock title %}

{% block content %}
    <h1>Login</h1>
    <form role="form" action="" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="submit" />
    </form>
    <p>
        <a href="{% url 'password_reset' %}">
            Forgot your password?
        </a>
    </p>
{% endblock content %}

url.py (code insame line still error)

from django.conf.urls import url, include
from django.contrib.auth.views import (
  password_reset, 
  password_reset_done, 
  password_reset_confirm, 
  password_reset_complete,)
from django.contrib import admin
from django.views.generic import TemplateView
from collection import views

urlpatterns = [
  url(r'^$', views.index, name='home'),
  url(r'^about/$', TemplateView.as_view(template_name='about.html'), name='about'),
  url(r'^contact/$', TemplateView.as_view(template_name='contact.html'), name='contact'),
  url(r'^thing/(?P<slug>[-\w]+)/$', views.thing_detail, name='thing_detail'),
  url(r'^things/(?P<slug>[-\w]+)/edit/$', views.edit_thing, name='edit_thing'),
  url(r'^accounts/password/reset/$', password_reset, {'template_name': 'registration/password_reset_form.html'}, name="password_reset"),
  url(r'^accounts/password/reset/done/$', password_reset_done, {'template_name': 'registration/password_reset_done.html'}, name="password_reset_done"), 
  url(r'^accounts/password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, {'template_name':'registration/password_reset_confirm.html'}, name="password_reset_confirm"),
  url(r'^accounts/password/done/$', password_reset_complete, {'template_name': 'registration/password_reset_complete.html'}, name="password_reset_complete"),
  url(r'^account/', include('registration.backends.simple.urls')),
  url(r'^admin/', admin.site.urls),
]

#7

Here is the error log on server.

(venv) tester@ubuntu:~/Desktop/projects/myhellowebapp$ python manage.py runserver
Performing system checks…

System check identified no issues (0 silenced).
November 24, 2016 - 08:03:23
Django version 1.10.2, using settings ‘hellowebapp.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[24/Nov/2016 08:03:27] “GET /accounts/password/reset/ HTTP/1.1” 200 985
Internal Server Error: /accounts/password/reset/
Traceback (most recent call last):
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py”, line 39, in inner
response = get_response(request)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/contrib/auth/views.py”, line 47, in inner
return func(*args, **kwargs)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/contrib/auth/views.py”, line 205, in password_reset
form.save(**opts)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py”, line 291, in save
user.email, html_email_template_name=html_email_template_name,
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py”, line 240, in send_mail
body = loader.render_to_string(email_template_name, context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/loader.py”, line 68, in render_to_string
return template.render(context, request)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/backends/django.py”, line 66, in render
return self.template.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 208, in render
return self._render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 199, in _render
return self.nodelist.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 994, in render
bit = node.render_annotated(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 961, in render_annotated
return self.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py”, line 39, in render
output = self.nodelist.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 994, in render
bit = node.render_annotated(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 961, in render_annotated
return self.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py”, line 61, in render
result = self.nodelist.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 994, in render
bit = node.render_annotated(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/base.py”, line 961, in render_annotated
return self.render(context)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py”, line 439, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/urls/base.py”, line 91, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File “/home/tester/Desktop/projects/myhellowebapp/venv/local/lib/python2.7/site-packages/django/urls/resolvers.py”, line 392, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns)
NoReverseMatch: Reverse for ‘django.contrib.auth.views.password_reset_confirm’ with arguments ‘()’ and keyword arguments ‘{u’uidb64’: ‘Mg’, u’token’: u’4ha-45b3cb0d855f5bfb768d’}’ not found. 0 pattern(s) tried: []
[24/Nov/2016 08:03:30] “POST /accounts/password/reset/ HTTP/1.1” 500 174730


#8

OK, I just save in wrong file type.

I should saved as

password_reset_email.txt

instead of

password_reset_email.html

Thanks for your help. ^^


#9

Yay, glad you figured it out!


#10

Hi Tracy,

I encountered the same problem until I came to this post. You might want to update the gumroad files ( it says “password_reset_email.txt”) if you can…thanks!


#11

Oh shoot, I see the issue. Looks like the epub or mobi is incorrect. Can you confirm that you were looking at either of these versions? PDF seems to be correct, just want to make sure I didn’t miss anything.


#12

I am using the PDF version, it says “password_reset_email.txt” on both however.




#13

Rargh, thanks for checking that. I wonder if Gumroad is caching the versions. I’ll see what I can do!