简体   繁体   English

使用长颈瓶棉花糖时访问棉花糖装饰器

[英]Accessing marshmallow decorators when using flask-marshmallow

I'm using flask-restful, flask-sqlalchemy and flask-marshmallow to build an API service. 我正在使用flask-restful,flask-sqlalchemy和flask-marshmallow来构建API服务。 I define the following - 我定义以下内容-

ma = Marshmallow(app)

However, trying to access the @validates decorator using ma throws an error. 但是,尝试使用ma访问@validates装饰器会引发错误。

@ma.validates('field1')

What am I doing wrong? 我究竟做错了什么? Is it better to directly use the marshmallow library and skip using flask-marshmallow altogether? 直接使用棉花糖库并完全跳过烧瓶棉花糖是否更好?

The problem is that you are trying to reach flask-marshmallow decorators in its API, however there is none. 问题是您正在尝试通过其API来访问flask-marshmallow装饰器,但是没有。

So you to understand if you need flask-marshmallow package, or only marshmallow is required. 因此,您可以了解是否需要flask-marshmallow包装,或者只需要marshmallow

Also to make things work, you need to use validates() decorator as it presented in docs 为了使事情正常进行,您还需要使用docs中提供的validates()装饰器

@validates('field1')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM