我正在使用 python、Django 并收到以下错误:
getattr(): attribute name must be string
location: val = getattr(obj, field)
if field in headers:
if not isinstance(field, str):
val = getattr(obj, field)
else:
val = getattr(obj, field.LastName)
if callable(val):
val = val()
if type(val) == unicode:
val = val.encode("utf-8")
row.append(val)
我尝试了许多代码变体,但都失败了。