''str' object has no attribute 'get' django rest framework

I'm trying to connect rest framework views to a template, the get method is working properly but when posting datas it gives me the error : enter image description here

enter image description here

views.py:

class Login(APIView):
    serializer_class = LoginSerializer
    permission_classes = [IsAnonymous, ]
    template_name = 'accounts/login.html'
    renderer_classes = [TemplateHTMLRenderer]
    style = {'template_pack': 'rest_framework/vertical/'}

    def get(self, request):
        serializer = self.serializer_class()
        return Response({'serializer': serializer, 'style': self.style})

    def post(self, request):
        payload = request.data
        serializer = self.serializer_class(data=payload)
        if serializer.is_valid():
            user = authenticate(request,
                                username=payload['username'],
                                password=payload['password']
                                )

            if user:
                login(request, user)
                response = {
                    'message': 'you logged in successfully!'
                }
                code = status.HTTP_200_OK
            else:
                response = {
                    'message': 'your username or password is wrong!'
                }
                code = status.HTTP_401_UNAUTHORIZED
        else:
            response = {
                'error': serializer.errors
            }
            code = status.HTTP_403_FORBIDDEN
        return Response(data=response, status=code)

I don't know where am I doing wrong , I appreciate if anyone can help me in this case



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source