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')
    
  • 相关阅读:
    HTTP协议
    php目录操作
    PHP有关类的相关知识
    PHP设计模式
    PHP类的继承
    PHP重写
    php类中成员
    php面向对象
    什么是SVN
    ThinkPHP5 初识路由
  • 原文地址:https://www.cnblogs.com/wangyingblock/p/13801198.html
Copyright © 2011-2022 走看看