Adesiyan Tope
Adesiyan Tope

Reputation: 49

AssertionError while working on django rest framework

I have this error, i don't know how to fix it

AssertionError: Expected view ListingView to be called with a URL keyword argument named "pk". Fix your URL conf, or set the .lookup_field attribute on the view correctly

class ListingView(RetrieveAPIView):
    queryset = Listing.objects.order_by('-list_date').filter(is_published=True)
    serializer_class = ListingDetailSerializer
    look_field = 'slug'

urlpatterns = [
    path('', ListingsView.as_view()),
    path('search/', SearchView.as_view()),
    path('<slug>/', ListingView.as_view())
]

Upvotes: 0

Views: 91

Answers (1)

Metalgear
Metalgear

Reputation: 3457

I think look_field should be changed into lookup_field.

class ListingView(RetrieveAPIView):
    queryset = Listing.objects.order_by('-list_date').filter(is_published=True)
    serializer_class = ListingDetailSerializer
    lookup_field = 'slug'

Upvotes: 1

Related Questions