+ 1

Isn't this code supposed to give me an authentication token.the login is also not working

I am using django rest framework TokenAuthentication hoping to get a response of the token. my frontend app is responding with a null, but when I check the network section i can see the token THE VIEW: class LoginView(APIVIew): serializer_class = LoginSerializer permission_classes =() def post(self,request): username=request.data.get("username") password = request.data.get("password") user = authenticate(username=username, password=password) if user: login(request,user) return Response({'token': user.auth_token.key}, status=status.HTTP_200_OK) else: return Response({'error':Wrong credentials'},status=status.HTTP_400_BAD_REQUEST) THE SERIALIZER: class LoginSerializer(serializers.ModelSerializer): class Meta: model=User fields=["username","password"]

16th Sep 2020, 3:21 PM
prime omondi
prime omondi - avatar
1 Answer
0
This code is working properly, the main problem was with the frontend. The axios data request was the major point of concern but it has been fixed.
18th Sep 2020, 3:33 PM
prime omondi
prime omondi - avatar