resource_fields{
'id':fileds.Integer,
'name':fields.String(attribute='private_name')
}
@marshal_with(resource_fields)
def get(self):
pass
使用attribute重命名字段名并不生效,这是什么情况?
resource_fields{
'id':fileds.Integer,
'name':fields.String(attribute='private_name')
}
@marshal_with(resource_fields)
def get(self):
pass
使用attribute重命名字段名并不生效,这是什么情况?
1 回答3.6k 阅读
552 阅读
resource_fields结构用于作为 marshal 函数的模板。在你的例子中,如果不指定attribute属性值时,默认等于key值为“name”。
attribute属性的作用不是重命名字段名,而是显式指定需要格式化的数据源的key值,所以首先你要确认你需要格式化的数据中是否存在“private_name”这个键值。