Итак, я пытаюсь выполнить функцию сброса пароля в django, но, получаю эту ошибку, не могу ее отладить.
Итак, это ошибка
Traceback (most recent call last):
File "/home/aman/.local/share/virtualenvs/stet-sikkim-project-D4VwjO1D/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/aman/.local/share/virtualenvs/stet-sikkim-project-D4VwjO1D/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/aman/.local/share/virtualenvs/stet-sikkim-project-D4VwjO1D/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/aman/.local/share/virtualenvs/stet-sikkim-project-D4VwjO1D/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/aman/.local/share/virtualenvs/stet-sikkim-project-D4VwjO1D/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/home/aman/Desktop/stet-sikkim-project/authentication/views.py", line 184, in post
user = request.objects.filter(email=email)
Exception Type: AttributeError at /authentication/request-password
Exception Value: 'WSGIRequest' object has no attribute 'objects'
Это код,
class RequestPasswordResetEmail(View):
def get(self, request):
return render(request, 'authentication/reset-password.html')
def post(self, request):
email = request.POST['email']
context = {
'values': request.POST
}
if not validate_email(email):
messages.error(request, 'Please enter a valid email')
return render(request, 'authentication/reset-password.html', context)
current_site = get_current_site(request)
user = request.objects.filter(email=email)
if user.exists():
email_contents = {
'user': user[0],
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user[0].pk)),
'token': PasswordResetTokenGenerator().make_token(user[0]),
}
link = reverse('reset-user-password', kwargs={
'uidb64': email_contents['uid'], 'token': email_contents['token']})
email_subject = 'Password Reset STET Sikkim'
reset_url = 'http://'+current_site.domain+link
email = EmailMessage(
email_subject,
'Please click the link below to reset your password, ignore if you did not made this request\n'+reset_url,
'noreply@stetsikkim.com',
[email],
)
email.send(fail_silently=False)
messages.success(
request, 'We have sent you an email to reset your password')
return render(request, 'authentication/reset-password.html')
Почему возникает эта ошибка, я не могу найти решение по переполнению стека и не могу отлаживать, помогите, если вижу ошибку в коде.