[Answered ]-NoReverseMatch at /reset-password-confirm/

1👍

Render with the uidb64 and token, so:

class UserResetPasswordConfirm(View):
    def get(self, request: HttpRequest, uidb64, token) -> HttpResponse:
        try:
            uid = force_str(urlsafe_base64_decode(uidb64))
            user_obj = User.objects.get(pk=uid)
        except:
            user_obj = None
        if user_obj is not None and account_activation_token.check_token(
            user_obj, token
        ):
            form: ResetPasswordConfirmForm = ResetPasswordConfirmForm()
        else:
            messages.error(request=request, message='توکن شما منقضی شده است')
        return render(
            request=request,
            template_name='reset/reset-confirm.html',
            context={'form': form, 'uidb64': uidb64, 'token': token},
        )

    # …

and then in the view use these to determine the URL:

<form class="form-inline" action="{% url 'reset_confirm' uidb64 token %}" method="post">

Note: redirect(…) [Django-doc] normally takes the name of the view and (optionally) kwargs, so you should not use reverse(…) [Django-doc]. You thus might want to rewrite redirect(redirect('reset_complete')) to redirect('reset_complete').


Note: Subclassing the View class directly is often not necessary. In this case your view looks like a FormView [Django-doc]. By using a FormView instead of a simple View, you often do not have to implement a lot of boilerplate code.

Leave a comment