python pydantic 字段 输入范围校验
2023-08-22 本文已影响0人
你好_3821
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 的值