ctx['location_ids'] = vals['location_ids']
我有一个很大的函数,所以我不会在这里发布它,但问题是当值作为整数时,一切都很顺利,但有时它vals['location_ids']
没有值,当它出现时我得到错误。vals['location_ids']
False
False
ctx['location_ids'] = vals['location_ids']
TypeError: 'bool' object has no attribute '__getitem__'
我怎样才能避免它,也许添加 hasattr?