From 2425675d3e3c237a81957b9add47aca96b29f9fe Mon Sep 17 00:00:00 2001 From: Aymane Date: Tue, 1 Aug 2023 23:21:48 +0100 Subject: [PATCH] fix ajax --- accounts/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accounts/views.py b/accounts/views.py index 8b128a6..4721372 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -34,14 +34,14 @@ class PasswordResetView(auth_views.PasswordResetView): def form_valid(self, form): response = super().form_valid(form) - if self.request.is_ajax(): + if self.request.headers.get('x-requested-with') == 'XMLHttpRequest': return JsonResponse({'status': 'ok', 'message': "If the email address exists in our database, you'll receive password reset instructions shortly."}, status=200) else: return response def form_invalid(self, form): response = super().form_invalid(form) - if self.request.is_ajax(): + if self.request.headers.get('x-requested-with') == 'XMLHttpRequest': return JsonResponse({'status': 'error', 'errors': form.errors}, status=400) else: return response