[Answered ]-Django – BaseSerializer.is_valid() takes 1 positional argument but 2 were given

1👍

rest-framework branch "3.9.x" (github)

def is_valid(self, raise_exception=False):
     ...

rest-framework branch "master" (github)

def is_valid(self, *, raise_exception=False):
     ...

so "master" now: is_valid() only accepts keyword argument "raise_exception=True":

class RegisterView(APIView):

  def post (self, request):
    create_user = UserSerializer(data=request.data)
    try:
    create_user.is_valid(raise_exception=True)
    ....

0👍

Change it into something like this:

def post(self, request):
    serializer = UserSerializer(data=request.data)
    if serializer.is_valid():
        user = serializer.save()
        return Response(user.data, status=status.HTTP_201_CREATED)

    the rest of your code...

Leave a comment