[Django]-Django rest Framework – Expected a list of items but got type "QuerySet"

2👍

It is that you have used many = True in the view when you pass the data to the serializer, but you are in fact only sending a single message.

def post(self, request, formate = None):
   serializer = SignupSerializer(data= signup_filtered_data)

See the actual answer:
Actual answer

1👍

A Much cleaner approach is using filters and serializer with a class-based view
A example of that is using mixins.

Mixins DjangoRest

FilterBackend DjangoRest

Pagination DjangoRest

Permissions Classes DjangoRest

filters.py

class SignupFilter(django_filters.FilterSet):

    class Meta:
        model = Signup
        fields = [
            'user_name',
        ]

views.py

class YourNameView(mixins.CreateModelMixin,
                   viewsets.GenericViewSet):

    permission_classes = [permissions.IsAuthenticated, ] # Permission Classes
    pagination_class = PageNumberPagination # Pagination Classes
    serializer_class = SignupSerializer # Your Serializer
    filter_backends = [DjangoFilterBackend] #This need to added on settings.py
    filter_class = SignupFilter # Your filter Class
    queryset = Signup.objects.all() 

    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

Leave a comment