2

I'm developing a Django app and I'm having trouble setting up reset password. I'm getting the following error:

Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'MQ', u'token': u'49v-cabad3fe98f5d9f64377'}' not found. 0 pattern(s) tried:

This is coming in my password_reset_email.html file which is:

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

I have the following in urls.py

(r'^registration/password_reset_confirm', 'django.contrib.auth.views.password_reset_confirm',
    {'template_name' : 'coursework/password_reset_confirm.html',
     'set_password_form' : SetPasswordForm,
     'post_reset_redirect' : 'coursework.views.list_comments'}),
(r'^registration/password_reset_done', 'django.contrib.auth.views.password_reset_done',
    {'template_name' : 'coursework/index.html'}),
(r'^registration/password_reset', 'django.contrib.auth.views.password_reset',
    {'password_reset_form' : PasswordResetForm,
     'template_name' : 'coursework/reset_password.html',
     'email_template_name' : 'coursework/password_reset_email.html',
     'subject_template_name' :'coursework/password_reset_subject.txt',
     'post_reset_redirect' : 'coursework.views.list_comments'}),

Clearly I'm doing something daft but I cannot work it out.

STACK TRACE ADDED

Environment:


Request Method: POST
Request URL: http://localhost:23080/registration/password_reset

Django Version: 1.9
Python Version: 2.7.11
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'coursework')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "C:\FCA\lib\django\core\handlers\base.py" in get_response
  134.                 resolver_match = resolver.resolve(request.path_info)

File "C:\FCA\lib\django\core\urlresolvers.py" in resolve
  374.             for pattern in self.url_patterns:

File "C:\FCA\lib\django\utils\functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "C:\FCA\lib\django\core\urlresolvers.py" in url_patterns
  417.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "C:\FCA\lib\django\utils\functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "C:\FCA\lib\django\core\urlresolvers.py" in urlconf_module
  410.             return import_module(self.urlconf_name)

File "C:\Python27\lib\importlib\__init__.py" in import_module
  37.     __import__(name)

Exception Type: SyntaxError at /registration/password_reset
Exception Value: invalid syntax (urls.py, line 24)
HenryM
  • 5,557
  • 7
  • 49
  • 105
  • Your `password_reset_confirm` view takes no keyword arguments. You should encode some in the url regex, e.g.: `r'^registration/password_reset_confirm/(?P\w+)/(?P\w+)'` – user2390182 Mar 02 '16 at 11:31

2 Answers2

6

I'm posting this answer to maybe help others with the same problem. I was getting the same error and did all the suggested solutions on the internet, with no luck!

at the end, thanks to this link's help, it worked!

solution: add url(r'^', include('django.contrib.auth.urls')), to the mainProject>urls.py

S_M
  • 290
  • 3
  • 18
  • This URL needs to be added to the BOTTOM of your urls.py if you're using custom templates, or custom authentication. But it needs to be BEFORE the url that brings in PasswordResetConfirmView. Unfortunatly it forces us to use the base django template for the actual action of inputting new passwords. – addohm Nov 14 '17 at 19:33
3

Your pattern does not accept uidb64 and token arguments. Change it to:

(r'^registration/password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm',
 {'template_name' : 'coursework/password_reset_confirm.html',
  'set_password_form' : SetPasswordForm,
  'post_reset_redirect' : 'coursework.views.list_comments'},
 name='password_reset_confirm'),
Selcuk
  • 57,004
  • 12
  • 102
  • 110
  • I've just tried this but I continue to get the same error - I think you've spotted something that would be the next error I would have received. – HenryM Mar 02 '16 at 11:57
  • @HenryM I also recognized that you are also missing the `name=` argument. See my updated answer. – Selcuk Mar 02 '16 at 11:59
  • that gives me an invalid syntax error for the line name='password_reset_confirm' – HenryM Mar 02 '16 at 12:22
  • I tested this and the syntax is valid. Please post stack trace of the error message. – Selcuk Mar 02 '16 at 14:03
  • I've posted the stack trace in the question. Is this because I'm running pyhton 2.7 on Google Appenigne? – HenryM Mar 03 '16 at 13:20
  • I'm working with Google Appengine and I've finally realised that I cannot use the Django email functionality because Appengine doesn't support it. I suspect this is what is causing the issue – HenryM Mar 04 '16 at 13:57
  • No, you have a SyntaxError somewhere in your urls.py that has nothing to do with email. Post whole urls.py so that we can debug. – Selcuk Mar 04 '16 at 23:17