我正在尝试获取包含特定单词的产品 这是我的观点
class DetailProductAPIViewName(generics.RetrieveAPIView):
serializer_class = ProductNestedSerializer
lookup_field = 'description'
def get_queryset(self):
description = self.kwargs['description']
print(description)
return Product.objects.filter(description__contains=description)
这是我的网址
url(r'^api/product/search/(?P<description>\w{0,50})/$', DetailProductAPIViewName.as_view(),name='list_productsearch_details'),
当我打印从kwargs获得的描述时,它返回在url中输入的参数,但在视图中返回
HTTP 404 Not Found
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"detail": "Not found."
}
感谢您的帮助
答案 0 :(得分:0)
将contains
更改为icontains
,
return Product.objects.filter(description__icontains=description)
icontains
返回不区分大小写的结果。