1

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 %}"
4
  • 1
    The uidb64 is empty? According to your re_path, it should contain at least one character. Commented Jul 24, 2018 at 13:41
  • @Sugumar - yes, the others User related views works Commented Jul 24, 2018 at 13:48
  • @WillemVanOnsem, yes but shouldn't PasswordResetconfirm generate uidb64 ? Commented Jul 24, 2018 at 13:49
  • @user3531631: it does, but it stores it in uid, not uidb. Commented Jul 24, 2018 at 13:49

1 Answer 1

2

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 %}"
Sign up to request clarification or add additional context in comments.

1 Comment

@user3541631: I think you need to use the html_email_template_name (well both, such that it generates a multipart email). Since some email clients do not render HTML, it is safer to also include a "text-only" version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.