TypeError:get_serializer_class()缺少1个必需的位置参数:“self”

2024-03-28 13:36:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用视图功能时出错,下面是我的回溯:

File "/Users/xxx/Desktop/xxx/Project/xxx/qiyun_admin_usermanage/api/views.py", line 40, in <module>
    class UserListAPIView(ListAPIView):
  File "/Users/xxx/Desktop/xxx/Project/xxx/qiyun_admin_usermanage/api/views.py", line 59, in UserListAPIView
    serializer_class = get_serializer_class()
TypeError: get_serializer_class() missing 1 required positional argument: 'self'

我的视图.py代码如下:

^{pr2}$

如果我把serializer_class = get_serializer_class()写在def get_serializer_class(self):方法的前面,我将 找不到错误。在


Tags: pyproject视图apigetadminusersviews
1条回答
网友
1楼 · 发布于 2024-03-28 13:36:23

您不需要定义serializer_class属性,因为您已经重写了get_serializer_class方法。拆下管路59。在

来自http://www.django-rest-framework.org/api-guide/generic-views/#attributes

serializer_class - The serializer class that should be used for validating and deserializing input, and for serializing output. Typically, you must either set this attribute, or override the get_serializer_class() method.

相关问题 更多 >