`basename` argument not specified, and could ' \

£可爱£侵袭症+ 提交于 2021-02-19 04:53:10

问题


I am getting the below error again and again.I am trying to solve it from morning but nothing is happening.

assert queryset is not None, 'basename argument not specified, and could ' \ AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a .queryset attribute.

models.py

class Language(models.Model):
    A = models.CharField(max_length=50)
    B = models.ForeignKey(User,on_delete=models.CASCADE,null=True)
    C = models.CharField(max_length=60)
    D = models.TextField(max_length=256)
    E = models.BooleanField(default=False)

serializers.py

class LanguageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Language
        fields = ("__all__")

views.py

class LanguageView(viewsets.ModelViewSet):
    queryset = Language.objects.all()
    serializer_class = LanguageSerializer

urls.py

router = routers.DefaultRouter()
router.register('ln/languages', views.LanguageView)

There are many more models(tables) in models.py, Every other model(table) is

working fine for getting results but Language model(table) is givin the error

assert queryset is not None, 'basename argument not specified, and could ' \ AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a .queryset attribute.


回答1:


Give a try

router.register('ln/languages', views.LanguageView, basename='ln-languages')

or

router.register('ln/languages', views.LanguageView, basename='languages')

More detail you can check the documentation django-rest-framework-routers



来源:https://stackoverflow.com/questions/55296191/basename-argument-not-specified-and-could

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!