0

I am using built-in Django authentication to send an email to reset a password. Sending the email works, but when I try and follow the link to the page to reset my password, Django changes the URL (kind of like a redirect I guess) and then is trying to resolve the URL to 'http://127.0.0.1:8000/registration/USER_ID/set-password', instead of 'http://127.0.0.1:8000/registration/USER_ID/TOKEN'. Django then throws an error: 'NoReverseMatch at /registration/reset/USER_ID/set-password/'

I don't have a file called "set-password" and nowhere in my code (templates, URLconf) do I have "set-password".

urlpatterns = [

...
...

path('password_reset/', auth_views.PasswordResetView.as_view(),
  name='password_reset'),

path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(),      
  name='password_reset_done'),

path('reset/<uidb64>/<token>/', 
  auth_views.PasswordResetConfirmView.as_view(),    
  name='password_reset_confirm'),

path('reset/done', auth_views.PasswordResetCompleteView.as_view(), 
  name='password_reset_complete'),
]

I am using the code found in the docs (https://docs.djangoproject.com/en/2.1/topics/auth/default/#using-the-views) for my URL matching, so I am not creating anything new. It seems like Django is removing the token from the URL?

Walker Sorlie
  • 53
  • 1
  • 1
  • 7

1 Answers1

0

So I figured out the answer if anybody else in the future has the same problem. In the "password_reset_confirm" template, I was setting the action of the form to action="{% url 'password_reset_confirm' %}", which was causing Django to attempt to construct that URL when the page was initially loading. Because 'password_reset_confirm' has parameters, I was getting the NoReverseMatch error (because I was not supplying any parameters in the action URL). Removing action from the form solves the problem.

Walker Sorlie
  • 53
  • 1
  • 1
  • 7