V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Aug 21, 2018 · 3244 views
    This topic created in 2813 days ago, the information mentioned may be changed or developed.
    可以用过下面方式定义不同的类型——

    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 replies    2020-04-20 19:12:52 +08:00
    dengqianyi
        1
    dengqianyi  
    OP
       Aug 21, 2018
    没有人在开发中使用 marshmallow 吗?
    iPhonePKAndroid
        2
    iPhonePKAndroid  
       Apr 14, 2019
    @dengqianyi 你好,遇到了和你一样的问题、请问有解决方案吗,比较需要、
    dengqianyi
        3
    dengqianyi  
    OP
       Apr 20, 2020 via Android
    @iPhonePKAndroid 原先这样设计的不对,换了设计当时解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2916 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:44 · PVG 14:44 · LAX 23:44 · JFK 02:44
    ♥ Do have faith in what you're doing.