返回主题:Python Web API 框架实践

知识卡片

普通读书笔记卡 · 3493.c

字段模型约束载荷

理解等级:中级

marshmallow 的 Schema 子类用字段对象声明载荷结构,字段可设置必填、取值范围、枚举约束,并可嵌套或继承已有模式。接口层把模式接到请求和响应处理时,校验规则才落实到端点;模式声明本身不等于业务状态校验。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 6 章《Building REST APIs with Python》(源文件:_epub-src/OEBPS/Text/06.htm) - 结论依据:原文展示 `Schema` 子类、字段类、取值约束与继承,并说明 marshmallow 模型用于验证请求和响应载荷。 - 原始内容:To create marshmallow models, we create subclasses of marshmallow’s Schema class . We define the models’ properties with the help of marshmallow’s field classes, such as String and Integer . Marshmallow uses these property definitions to validate a payload against a model.