我有一个函数基础视图,它从 URL http://127.0.0.1:8000/api/v1/contest/0b36d92a-51a7-4752-9df1-e5f2733116c1/paintings/获取 2 个参数
@api_view(['GET',])
@permission_classes([AllowAny])
def Contest_detail_by_id_and_category(request, id, category_name):
if request.method == 'GET':
artcontests = Artwork.objects.filter(artcontest = id,category__name__iexact=category_name)
serializer = ArtworkSerializer(artcontests, many=True)
# serializer = ArtworkSerializer(artcontests, many=True)
return Response(serializer.data)
这给出了正确的结果,但是当我尝试在 generics.ListAPIView 中编写相同的功能时,它给出了
/api/v1/contesty/0b36d92a-51a7-4752-9df1-e5f2733116c1/paintings/ 'method' 类型的对象的 TypeError 没有 len()
class Contest_detail_by_id_category(generics.ListAPIView):
serializer_class = ArtworkSerializer1(many=True)
permission_classes = [AllowAny]
def queryset(self):
queryset = Artwork.objects.filter(artcontest = self.kwargs['id'],category__name__iexact=self.kwargs['category_name'])
# queryset = self.get_queryset()
serializer = ArtworkSerializer1(queryset)
return Response(serializer.data)
谁能帮助我 - 如何在generics.ListAPIView或viewsets.ModelViewSet中编写正确的视图