djangodjango-viewsdjango-authentication

Password Reset functionality inheriting from Django clases - reverse url issues ('uidb64')


I want to create a Password Reset functionality but changing the templates.
So I'm inheriting from Django classes.

After I insert the email to reset password, I ge the following error:

NoReverseMatch at /accounts/password-reset/

Reverse for 'confirm_reset_password' with keyword arguments '{'uidb64': '', 'token': '4y5-9ae986836e35f95b842c'}' not found. 1 pattern(s) tried: ['accounts\/password-reset-confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']

I think the issue is that 'uidb64', but I don't know why is empty.

Views:

class CustomPasswordResetView(PasswordResetView):

    form_class = CustomPasswordResetForm
    email_template_name = 'account/password_reset_email.html'
    template_name = 'account/password_reset.html'

class UserPasswordResetConfirmView(PasswordResetConfirmView):

    pass

Form:

class CustomPasswordResetForm(PasswordResetForm):

    email = forms.EmailField(widget=TextInputWidget)

Urls:

path('password-reset/', UserPasswordResetView.as_view(), name='reset_password'),

re_path(r'^password-reset-confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
UserPasswordResetConfirmView.as_view(), name='confirm_reset_password')

in reset template:

<form action="" method="post">
  {% csrf_token %}
  <div class="row ">
    {{ form.email }}
  </div>
  <div class="l-action">
    <input type="submit" class="button" value="Reset my password">
  </div>
</form>

In email template:

a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uidb token=token %}"

Solution

  • I think your email template contains an error. You write:

    a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uidb token=token %}"

    But the uidb64 parameter should, according to the documentation [Django-doc] have as parameter the uid variable, so:

    a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uid token=token %}"