I'm getting the above error when creating token, here's the code:
from rest_framework import generics, permissions
from rest_framework.response import Response
from knox.models import AuthToken
from .serializers import UserSerializer, RegisterSerializer
class RegisterAPI(generics.GenericAPIView):
serializer_class = RegisterSerializer
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.save()
return Response({
"user": UserSerializer(user, context=self.get_serializer_context()).data,
"token": AuthToken.objects.create(user)
})
what am I doing wrong here
AuthToken
as well, like you did with the user (or pass an attribute of that token that can be converted to JSON (like astr
,int
, etc.). AnAuthToken
itself is, at least not without some extra logic, serializable). – EmulateUserSerializer
. – Emulatedjango-rest-knox
. I have a project withdjango-rest-know v 3.6.0
using the code you have in the post. I'm just starting an new project (using version 4.0.1), and I've had to add the[1]
to the token serialization. – Westland