# 定义user类型和user列表类型
from wsme import types as wtypes class User(wtypes.Base): name = wtypes.text age = int class Users(wtypes.Base): users = [User]
#实现API逻辑
class UsersController(rest.RestController): @expose.expose(Users) def get(self): user_info_list = [ { 'name': 'Alice', 'age': 30, }, { 'name': 'Bob', 'age': 40, } ] users_list = [User(**user_info) for user_info in user_info_list] return Users(users=users_list)
转自: https://segmentfault.com/a/1190000004004179?utm_source=tuicool&utm_medium=referral