The QuerySet value for an exact lookup must be limited to one result using slicing-Django

前端 未结 3 2034
星月不相逢
星月不相逢 2021-01-13 00:37

I\'m building a news website.While I tried to get the list of relative news which have the same tags.The error said:The QuerySet value for an exact lookup must be li

3条回答
  •  一个人的身影
    2021-01-13 01:17

    Generally this error occurs when we use model queryset at the place of django models object. In the given question you have done the same. "Objects.filter" returns the model query set there can be single or multiple django model objects, but "objects.get" returns single django model object. Or we can use .last() and .first() with "objects.filter".

提交回复
热议问题