Home > database >  AssertionError while working on django rest framework
AssertionError while working on django rest framework

Time:05-21

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())
]

CodePudding user response:

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'

Hope it could help.

  • Related