zoukankan      html  css  js  c++  java
  • 报错: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')
    
  • 相关阅读:
    mysql面试知识点
    计算机网络
    BFS
    拓扑排序
    双指针
    回溯算法
    hash表 算法模板和相关题目
    桶排序及其应用
    滑动窗口
    贪心算法
  • 原文地址:https://www.cnblogs.com/wangyingblock/p/13801198.html
Copyright © 2011-2022 走看看