首页 > 编程语言 >cnblog_fastapi 中的 schemas 和 models 的区别 - python 后端实战经验分享 - SegmentFault 思否

cnblog_fastapi 中的 schemas 和 models 的区别 - python 后端实战经验分享 - SegmentFault 思否

时间:2023-02-12 21:13:18浏览次数:54  
标签:models fastapi py 思否 file Pydantic schemas

python fastapi schema和model的区别

To avoid confusion between the SQLAlchemy models and the Pydantic models, we will have the file model......

来自 fastapi 的文档 Create the Pydantic models

To avoid confusion between the SQLAlchemy models and the Pydantic models, we will have the file models.py with the SQLAlchemy models, and the file schemas.py with the Pydantic models.

These Pydantic models define more or less a "schema" (a valid data shape).

So this will help us avoiding confusion while using both.

大概意思就是:

  • schemas.py 放 pydantic 的模型
  • models.py 放 sqlalchemy、peewee 的模型

标签:models,fastapi,py,思否,file,Pydantic,schemas
From: https://www.cnblogs.com/zhuoss/p/17114712.html

相关文章