日常踩坑:valueerror: the queryset value for an exact lookup must be limited to one result using slicing.

使用django分页器分页的时候报如上错误, 一直以为是自己分页功能调用的函数和参数不对。。。。因为就是在取指定页数据的时候的那一行代码报错。。caocaocao......

在stackoverflow 查到解决办法, 原来是查询结果集的问题。。

之前是这样的

articles = Article.objects.filter(category=category)

然后就报错

然后改成这样

articles = Article.objects.filter(category__in=category)

就是在查询条件的属性那里加上  __in  就不会报错了。。。。

 

附上原解决办法的网站

https://stackoverflow.com/questions/56805734/valueerror-the-queryset-value-for-an-exact-lookup-must-be-limited-to-one-result

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用np.where函数时,如果传入的数组具有多个元素,会出现ValueError: The truth value of an array with more than one element is ambiguous的错误。这个错误是因为在条件判断时,出现了多个元素的真值无法确定的情况。为了解决这个问题,可以使用np.any()或np.all()方法来判断数组的真值。np.any()方法用于判断数组中是否存在至少一个True值,而np.all()方法用于判断数组中的所有值是否都为True。通过使用这些方法,可以避免出现ValueError错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [python-numpy-ValueError: The truth value of an array with more than one element is ambiguous.](https://blog.csdn.net/PSpiritV/article/details/124339801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [使用numpy遇到ValueError: The truth value of an array with more than one element is ambiguous](https://blog.csdn.net/weixin_45370422/article/details/122247903)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值