请告诉我,您如何访问在 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)
请您参考如下方法:
根据文档你应该使用.query_params
request.query_params is a more correctly named synonym for request.GET.
更多详情 query_params
