from pydantic import BaseModel, Field
class TestModel(BaseModel):
name: str
level: T.Optional[int] = Field(0, ge=0, le=9)
level 字段限制只能是 0<=level <= 9 的值
from pydantic import BaseModel, Field
class TestModel(BaseModel):
name: str
level: T.Optional[int] = Field(0, ge=0, le=9)
level 字段限制只能是 0<=level <= 9 的值
本文标题:python pydantic 字段 输入范围校验
本文链接:https://www.haomeiwen.com/subject/ghsumdtx.html
网友评论