AssertionError: `basename` argument not specified, and could not automatical....

错误:AssertionError: basename argument not specified, and could not automatical…

原因:在views中没有定义queryset字段时在路由的注册必须加上basename
例如:在views.py中有

class GoodsListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
    queryset = Goods.objects.all()  # 有queryset
    ...
    ...

所以在urls.py中便可以这样配置

router = DefaultRouter()
router.register(r'goods', GoodsListViewSet)

解决方法

加上basename即可

class SmsCodeViewSet(CreateModelMixin, GenericViewSet):
		.... # 没有queryset
router = DefaultRouter()
router.register(r'codes', SmsCodeViewSet, basename='codes')

你可能感兴趣的:(django)