QuerySet, Object has no attribute id - Django

前端 未结 4 733
死守一世寂寞
死守一世寂寞 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:38

    In most cases you do not want to handle not existing objects like that. Instead of

    ad[0].id
    

    use

    get_object_or_404(AttachedInfo, attachedMarker=m.id, title=title)
    

    It is the recommended Django shortcut for that.

提交回复
热议问题