Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以传入字段名称而不是硬编码的“last_name”?
for item in queryset: to_json.append(item.last_name)
你可以做:
for item in queryset: to_json.append(getattr(item, 'last_name'))
这允许'last_name'成为一个变量而不是硬编码的字符串。
'last_name'