queryset = demo.objects.filter(name="non_existent_name")
if queryset.exists():
serializer = DemoSerializer(queryset, many=True)
return Response(serializer.data)
else:
return Response(status=status.HTTP_404_NOT_FOUND)
With an empty queryset - I am expecting a 404, but instead get a 200 with an empty serialized Response. What is wrong with my code? Why does exists() not work as expected?