# 定义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

WSME api controller嵌套使用wtypes的更多相关文章

  1. Only one complex type allowed as argument to a web api controller action.

    错误内容: message":"An error has occurred.","exceptionMessage":"Only one c ...

  2. 重构Web Api程序(Api Controller和Entity)续篇

    昨天有写总结<重构Web Api程序(Api Controller和Entity)>http://www.cnblogs.com/insus/p/4350111.html,把一些数据交换的 ...

  3. MVC Controller 链接到 API Controller 以及反向链接

    MVC Controller 链接到 API Controller 以及反向链接 问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controll ...

  4. 测试 ASP.NET Core API Controller

    本文需要您了解ASP.NET Core MVC/Web API, xUnit以及Moq相关知识. 这里有xUnit和Moq的介绍: https://www.cnblogs.com/cgzl/p/917 ...

  5. There is no action xxxFun defined for api controller api/subitem

    在使用abp的框架时,访问某个接口方法出现错误: There is no action xxxFun defined for api controller api/subitem 原因:肯定是访问的接 ...

  6. [水煮 ASP.NET Web API2 方法论](1-4)从 MVC Controller 链接到 API Controller 以及反向链接

    问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controller 的直接链接,或者反向链接. 解决方案 可以使用 System.Web.Htt ...

  7. Rest Web Api Controller 返回JSON格式大小写

    public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Ro ...

  8. Yii2 components api/controller

    When we wrote API, those controllers need to implement the following feature: 1. return JSON format ...

  9. ASP.NET Web API Controller 是怎么建成的

    先看ASP.NET Web API 讯息管线: 註:为了避免图片太大以至于超过版面,上图中的「HTTP 讯息处理程序」区块省略了 HttpRoutingDispatcher 处理路由分派的部分.「控制 ...

随机推荐

  1. SharePoint 2013技巧分享系列 - 同步Exchange显示高清用户照片

    在“SharePoint 2013技巧分享系列 - Active Directory同步显示用户照片”文中介绍了如何同步Active Directory显示用户照片,但是同步完成后,用户照片尺寸和清晰 ...

  2. jquery easyui 1.4.1 API( CHM版)

    ChangeLog Bug The combogrid has different height than other combo components. fixed. datagrid: The r ...

  3. Mysql查看执行计划-explain

    最近生产环境有一些查询较慢,需要优化,于是先进行业务确认查询条件是否可以优化,不行再进行sql优化,于是学习了下Mysql查看执行计划. 语法 explain <sql语句>  例如: e ...

  4. 前端ps常用的小技巧

    一些很简单的例子,知道的就当看乐子. 1.T 是文字的  可以从矢量图中查看文字的大小 字体 颜色,具体就是T  选择一段文字,点确定,点击属性栏最后一个可以看详细信息.又字体,行高,颜色.如果要选取 ...

  5. Django-跨站请求

    //用户验证Tonken 在Html 中 设置一个Token {% csrf_token %} //在代码Views.py 中返回值添加 context_instance=RequestContext ...

  6. 解决:/bin/sh: 1: /home/**/custom_app.sh: Permission denied错误

    出现如下错误,一般是执行权限不够. /bin/sh: : /home/custom_app.sh: Permission denied 解决方法是:cd 到此文件目录,对提示的文件赋予可执行权限或读写 ...

  7. transition

    transition: all 所有属性都将获得过渡效果. property 定义应用过渡效果的 CSS 属性名称列表,列表以逗号分隔 transition-duration 规定完成过渡效果需要多少 ...

  8. Linux 远程复制文件

    Linux 远程复制文件 如果想把机器A上面的dir目录下面的所有文件复制到机器B的dir目录下,我们可以使用nc命令来完成 在机器A的dir目录下面执行: tar -czf - * | nc -l ...

  9. bzoj4571: [Scoi2016]美味

    4571: [Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MB Submit: 275 Solved: 141 [Submit][Status][ ...

  10. CSS3学习(圆角、图片、阴影、背景、渐变、文本、字体、2D、3D、过渡等)

    matrix CSS3 1.  圆角 border-radius:边框圆角的圆角半径 四个值:第一个值为左上角,第二个值为右上角,第三个值为右下角,第四个值为左下角. 三个值:第一个值为左上角, 第二 ...