从ReadOnlyModelViewSet获取查询字段

时间:2017-10-02 12:55:27

标签: python django django-rest-framework

请告诉我,您如何访问GET请求中发送到以下表单的ViewSet的字段:

class MyViewSet(ReadOnlyModelViewSet):
    http_method_names = ['get']
    queryset = User.objects.all()
    serializer_class = MySerializer
    permission_classes = (AllowAny,)

    def list(self, request, *args, **kwargs):
        request.data # < attempt to access this attribute will return an empty dictionary

        return super().list(request, args, kwargs)

1 个答案:

答案 0 :(得分:2)

按文档,您应该使用.query_params

  

request.query_params是request.GET。

的更正确命名的同义词

更多详情query_params