报错:AssertionError: `basename` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.
写一些公共接口时,报错:
经排查发现:
当viewset中没有定义queryset字段时在路由的注册必须加上basename:
例如:在views.py这种,定义了queryset字段
class PwdConfigViewSet(component_viewsets.ModelViewSet):
queryset = PwdConfig.objects.filter() #定义了queryset字段
....
.....
在urls.py中便是如下的写法:
router = routers.DefaultRouter(trailing_slash=True)
router.register(r'pwd_config', views.PwdConfigViewSet)
如果在views.py中没有定义queryset字段:
class CommonViewSet(component_viewsets.ModelViewSet):
serializer_class = serializers.Serializer
......
......
则在urls.py中,需要加上basename:
router = routers.DefaultRouter(trailing_slash=True)
router.register(r'common', views.CommonViewSet, basename='common')