V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dengqianyi
V2EX  ›  Python

关于在 flask-restplus 中使用 marshmallow 的问题

  •  
  •   dengqianyi · 2018-08-21 15:48:29 +08:00 · 2418 次点击
    这是一个创建于 2046 天前的主题,其中的信息可能已经有所发展或是发生改变。
    可以用过下面方式定义不同的类型——

    A= news_api.model('A', {
    'content': fields.Integer(required=True, description=''),
    'type': fields.String(required=True, default='a'),
    })

    B= news_api.model('B', {
    'content': fields.Integer(required=True, description=''),
    'type': fields.String(required=True, default='b''),
    })

    C= news_api.model('C', {
    'content': fields.Integer(required=True, description=''),
    'type': fields.String(required=True, default='c'),
    })

    A B C 类型的主要区别在 ‘ type ’字段,type 分别指定是 a b c

    我的问题是,如何定义一个类,可以校验如下的 json 数据:
    {
    "data":[
    {A},
    {B},
    {C}
    ]
    }
    3 条回复    2020-04-20 19:12:52 +08:00
    dengqianyi
        1
    dengqianyi  
    OP
       2018-08-21 22:52:31 +08:00
    没有人在开发中使用 marshmallow 吗?
    iPhonePKAndroid
        2
    iPhonePKAndroid  
       2019-04-14 18:08:31 +08:00
    @dengqianyi 你好,遇到了和你一样的问题、请问有解决方案吗,比较需要、
    dengqianyi
        3
    dengqianyi  
    OP
       2020-04-20 19:12:52 +08:00 via Android
    @iPhonePKAndroid 原先这样设计的不对,换了设计当时解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3377 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.