-1

I am having a problem with password reset on a django 1.6 site. urls.py has:

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
   'django.contrib.auth.views.password_reset_confirm',
   name='password_reset_confirm'

And when I click on the Reset my password link I get:

NoReverseMatch at /user/password/reset/
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'Mw', u'token': u'4bs-b5728359cb279d542120'}' not found. 1 pattern(s) tried: ['reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>.+)/$']

Here is the traceback:

Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in password_reset
  158.             form.save(**opts)
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/forms.py" in save
  256.             email = loader.render_to_string(email_template_name, c)
File "/usr/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  164.         return t.render(Context(dictionary))
File "/usr/local/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/usr/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/usr/local/lib/python2.7/site-packages/django/template/base.py" in render
  840.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/site-packages/django/template/base.py" in render_node
  854.         return node.render(context)
File "/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  447.                         six.reraise(*exc_info)
File "/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  433.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  536.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  456.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /user/password/reset/
Exception Value: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'Mw', u'token': u'4bs-b5728359cb279d542120'}' not found. 1 pattern(s) tried: ['reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>.+)/$']
Larry Martell
  • 3,526
  • 6
  • 40
  • 76
  • Have you looked at the django 1.6 source around this functionality it gives you examples of the regexs django is using to validate the urls. https://github.com/django/django/blob/1.6.11/django/contrib/auth/urls.py#L16 – Matt Seymour May 10 '16 at 16:02
  • Possible duplicate of [Django-nonrel + Django-registration problem: unexpected keyword argument 'uidb36' when resetting password](http://stackoverflow.com/questions/6323852/django-nonrel-django-registration-problem-unexpected-keyword-argument-uidb36) – Rahul Gupta May 10 '16 at 16:03
  • This has nothing to do with the regexp, nor is it the same as that other question. The issue seems to be that part is in `uidb36` and part is in `uidb64` – Larry Martell May 10 '16 at 16:40
  • Please show the full traceback. – Alasdair May 10 '16 at 16:50
  • Question updated with traceback. – Larry Martell May 10 '16 at 16:52

1 Answers1

2

Your first problem: (which you've now fixed in the question)

You need to update the regex to include _\-, as well as changing the name uidb36 to uidb64. It should be:

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
    'django.contrib.auth.views.password_reset_confirm',
    name='password_reset_confirm'
),

Your second problem:

You need to update your registration/password_reset_email.html email template to use uidb64 instead of uidb36. The example email template given in the docs is:

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

This is all covered in the Django 1.6 release notes.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Yes, I have it as `uidb64`. The issue is as I said in my original post, that it's failing with `Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'Mw', u'token': u'4bs-bd0dd5db5e44f6a33c5e'}' not found. 1 pattern(s) tried: ['password_reset_confirm/(?P[0-9A-Za-z]+)-(?P.+)/$']` – Larry Martell May 10 '16 at 16:35
  • You're not reading my answer or the release notes carefully enough. You have `(?P[0-9A-Za-z])`. It should be `(?P[0-9A-Za-z_\-])`. – Alasdair May 10 '16 at 16:40
  • I made that change. I now have `url(r'^reset/(?P[0-9A-Za-z_\-]+)/(?P.+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'` but the error I am getting has `uidb36` This is the error I get now: `NoReverseMatch at /user/password/reset/ Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb36': 'Mw', u'token': u'4bs-b5728359cb279d542120'}' not found. 1 pattern(s) tried: ['reset/(?P[0-9A-Za-z_\\-]+)/(?P.+)/$']` – Larry Martell May 10 '16 at 16:42
  • Try generating a new password reset link and see if that works. If that doesn't work, please update your question with the full traceback. – Alasdair May 10 '16 at 16:49
  • Thanks. Once I fixed `registration/password_reset_email.html` it works. – Larry Martell May 10 '16 at 17:27