[Django]-Django-rest-auth error – save() takes 1 positional argument but 2 were given

2👍

Because your custom registration view inherits from RegisterView,perform_create method define in RegisterView will call your serializer’s save method with a request object based on the implementation and since your serializer inherits from ModelSerializer, the save method does not take any positional argument hence the error.

CustomUserSerializer needs to define a save method that takes the request object as an argument. Check this exempt below from django-rest-auth configuration

The custom REGISTER_SERIALIZER must define a def save(self, request) method that returns a user model instance.

I’ll suggest you take a look at the implementation of the default REGISTER_SERIALIZER it’ll guide how your custom serializer should look.

1👍

The Problem is this:

django-rest-auth implements custom RegisterSerializer where the save method takes one additional positional argument request.

  def save(self, request):

This serializer is used by RegisterView from djang-rest-auth.

Normal serializer save method looks like this:

  def save(self, **kwargs):

You use your custom serializer in your view which parent is django-rest-auth RegisterView but your save method does not have the positional request argument, hence the problem.

And the logic in RegisterView assumes correct serializer implementation.

Try to use RegisterSerializer as parent to your serializer – you just need to investigate if it is straigtforward or you need to add/implement something else.

But it might be bit tricky.

But as it seems, you have custom model, custom serializer, custom view – i dont see any reason to use django-rest-auth RegisterView. Just implement your registration view.

Leave a comment