在Django Rest框架上工作时的主张
我有一个错误,我不知道如何
使用名为“ pk”的URL关键字参数来调用它:预期视图列表视图。修复您的URL conf或在视图上正确设置.lookup_field
属性
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())
]
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())
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
look_field
应将其更改为lookup_field
。I think
look_field
should be changed intolookup_field
.