2021年2月5日星期五

Django Knox-Rest Authentication Receives 500 Error on Login

I'm working on setting up a Django knox-rest framework for my rest api. I'm using Postman to test the login and after executing the request, my API returns a 500 error along with a stack dump. The dump returned to Postman is showing me the following error:

AttributeError at /users/api/auth/login  'LoginSerializer' object has no attribute 'validated_data'  

a snippet from my api.py file:

class LoginAPI(generics.GenericAPIView):      serializer_class = LoginSerializer      permission_classes = ()        def post(self, request, *args, **kwargs):          serializer = self.get_serializer(data=request.data)          serializer.is_valid(raise_exception=True)          user = serializer.valiated_data          _, token = AuthToken.objects.create(user)          return Response({              "user": UserSerializer(user, context=self.get_serializer_context()).data,              "token": token          })  

the snippet from my serializers.py file:

  class LoginSerializer(serializers.Serializer):      username = serializers.CharField()      password = serializers.CharField()        def validate(self, data):          user = authenticate(**data)          if user and user.is_active:              return user          raise serializers.ValidationError("Incorrect Credentials")  

The server starts clean and no errors are logged to the console other than the Post request and the 500 error. I have to go to Postman to see the dump with the above error.

I've tried just about everything I can think of or find to try without getting it figured out. So any help would be appreciated.

https://stackoverflow.com/questions/66072905/django-knox-rest-authentication-receives-500-error-on-login February 06, 2021 at 10:03AM

没有评论:

发表评论