mbc
mbc

Reputation: 101

AssertionError: `base_name` argument not specified

i'm trying to add a parameter of a model to a URL pattern, as such:

http://111.111.11.111:8080/resultados/image.jpg

where nome_ficheiro = image.jpg (nome_ficheiro is a model parameter, see below)

But i'm getting the following error:

 File "/usr/local/lib/python2.7/dist-packages/rest_framework/routers.py", line 139, in get_default_base_name
    assert queryset is not None, '`base_name` argument not specified, and could ' \
AssertionError: `base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.

The URL pattern:

    router = routers.DefaultRouter()
    urlpatterns = [url(r'^', include(router.urls))]
    router.register(r'resultados/(?P<nome_ficheiro>.+)/$',resultUploadView.as_view({'get': 'get_queryset'}))

The view:

class resultUploadView(generics.ListAPIView):
    serializer_class = resultSerializer
    def get_queryset(self):
        nome = self.kwargs['nome_ficheiro']
        return labelResult.objects.filter(nome_ficheiro=nome)

The model:

 class labelResult(models.Model):
    nome_ficheiro   = models.CharField(max_length=120)
    especie         = models.CharField(max_length=120)
    zona            = models.CharField(max_length=120)
    data            = models.CharField(max_length=120)

USING: Python 2.7.12 and DRF 3.6.3

EDITS:

urls.py:

router.register(r'results/(?P<nome_ficheiro>.+)/$', resultUploadView.as_view({'get': 'get_queryset'}), base_name='img_name')

still not working, getting the same error

Upvotes: 1

Views: 5565

Answers (2)

Vijay Gawade
Vijay Gawade

Reputation: 51

replace "base_name" to "basename"

Upvotes: 1

wim
wim

Reputation: 362707

You may name the route when you add it:

router.register(
    r'the-url_pattern$',
    TheViewSet,
    base_name='put-something-here',
)

As an aside, it's strange to specify both queryset class attribute and get_queryset method, and this could be what was confusing DRF. Pick one way or the other.

Upvotes: 2

Related Questions