when I try to login in from the form that i created in react.js and connected it with django i face error (User matching query does not exist.)
I think the problem here in views.py but i couldn’t solve it for days
from django.http import JsonResponse, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.views import APIView
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from .serializers import UserSerializer
from .models import User
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
#permission_classes = [IsAuthenticated]
class UserDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
#permission_classes = [IsAuthenticated]
@csrf_exempt
def user_login(request):
email = request.POST['email']
password = request.POST['password']
formValues = User.objects.get(email= email, password= password)
if formValues:
return JsonResponse ({'bool':True #, 'user_id':formValues.id
})
else:
return JsonResponse ({'bool':False})
here is model.py
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
username = models.CharField(max_length=50, null=True , blank= True)
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
def __str__(self):
return self.email
def get_name(self):
return self.username
errer from console
DoesNotExist at /api/user-login
User matching query does not exist.
Request Method: POST
Request URL: http://127.0.0.1:8000/api/user-login
Django Version: 4.0.3
Exception Type: DoesNotExist
Exception Value:
User matching query does not exist.
Exception Location: /home/monerahalbeshry/.local/lib/python3.8/site-packages/django/db/models/query.py, line 496, in get
Python Executable: /usr/bin/python3
Python Version: 3.8.10
Python Path:
['/home/monerahalbeshry/Desktop/team10-backend/env/GoCourses',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/monerahalbeshry/.local/lib/python3.8/site-packages',
'/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Sun, 20 Mar 2022 09:38:05 +0000
anyone to help please