QuerySet, Object has no attribute id - Django

前端 未结 4 714
死守一世寂寞
死守一世寂寞 2021-02-01 04:24

I\'m trying to fetch the id of certain object in django but I keep getting the following error Exception Value: QuerySet; Object has no attribute id. my function in views.py

4条回答
  •  無奈伤痛
    2021-02-01 04:57

    this line of code

    at = AttachedInfo.objects.filter(attachedMarker=m.id, title=title)

    returns a queryset

    and you are trying to access a field of it (that does not exist).

    what you probably need is

    at = AttachedInfo.objects.get(attachedMarker=m.id, title=title)
    

提交回复
热议问题