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 usereverse(…)
[Django-doc]. You thus might want to rewriteredirect(redirect('reset_complete'))
toredirect('reset_complete')
.
Note: Subclassing the
View
class directly is often not necessary. In this case your view looks like aFormView
[Django-doc]. By using aFormView
instead of a simpleView
, you often do not have to implement a lot of boilerplate code.
Source:stackexchange.com