IndexError list index out of range Django获取ORM模型的某个字段

score=stu.objects.filter(name=name)[0].__getattribute__('score')

#模型对象.__getattribute__(字段名称)   

IndexError : list index out of range

第1种可能情况


list[index]index超出范围


第2种可能情况


list是一个空的 没有一个元素 
进行list[0]类型操作就会出现该错误   

猜你喜欢

转载自blog.csdn.net/weixin_41514525/article/details/88074925