lUsers从User表中获取出来,与lUser.id进行对比
报错
AttributeError at /ClassUser/
'dict' object has no attribute 'id'
查看User变量,已经序列化处理
user
{'City': u'\u77f3\u5bb6\u5e84', 'CreateTime': datetime.datetime(2015, 12, 12, 11, 59, 32), 'IsDelete': False, 'ModifyTime': datetime.datetime(2016, 5, 18, 10, 8, 20), 'Nick': u'\u4eca\u5929\u661f\u671f5', 'PhoneNumber': u'18584050213', 'Provence': u'\u6cb3\u5317', 'Role': u'\u7ba1\u7406\u5458', 'Sex': u'\u7537', 'UserName': u'yinshunyao119', '_FILE_HeaderFigure': u'_User_2XbNIvwVEayfsfhC20160513_223856', 'country': u'\u4e2d\u56fd', 'hxUserName': u'm18584050213', 'id': 4L}
lUser变量,看出lUser还是User对象
lUser <User: xxx>
解决办法
将if user.id == lUser.id: 修改成
if user[‘id’] == lUser.id:
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:【服务后端】Django对比查询结果中的id时报错’dict’ object has no attribute ‘id’ - Python技术站