from flask_smorestfields import Uploadclass UploadArgSchemaArgSchema file = Upload description=待上传文件 required=True error_messages=required 待上传文件不能为空 如果fule字段有三个选择1和2都是上传默认图片如果是3的话就上传图片且三个
To achieve this requirement, you can modify the UploadArgSchema class as follows:
from flask_smorest.fields import Upload
from marshmallow import validate
class UploadArgSchema(ArgSchema):
file = Upload(
description='待上传文件', required=True, error_messages={'required': '待上传文件不能为空'},
validate=validate.OneOf(['1', '2', '3'])
)
In the above code, we added the validate argument to the Upload field and specified validate.OneOf(['1', '2', '3']) as the validator. This ensures that only the values '1', '2', or '3' are allowed for the file field
原文地址: https://www.cveoy.top/t/topic/ihts 著作权归作者所有。请勿转载和采集!