Search code examples
djangodjango-modelsdjango-rest-frameworkdjango-serializer

`basename` argument not specified, and could ' \


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.


Solution

  • 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