Home » Django & REST Api » Solved: {“non_field_errors”: [“Expected a list of items but got type \”dict\”.”]}

Solved: {“non_field_errors”: [“Expected a list of items but got type \”dict\”.”]}

When we were working with Django rest framework and trying to design a response JSON, we got the following error when tried to push the JSON using http POST.

{"non_field_errors": ["Expected a list of items but got type \"dict\"."]}

This error was occurring because we tried to push single JSON object, but in code we had written as “many=True”, in views.py

 def post(self, request, format=None):
    serializer = UserSerializer(data=request.data, many=True)
    if serializer.is_valid():
       serializer.save()
       return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)

Solution : change views.py to remove “many=True” while getting serializer

def post(self, request, format=None):
    serializer = UserSerializer(data=request.data)
    if serializer.is_valid():
       serializer.save()
       return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment