Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以,我有带有字符串字段的 pydantic 模型
class MyPydanticModel(BaseModel): name: Optionsl[str]
我想让这个字段的最大长度为 10。我该怎么做?
您可以使用constr:
constr
from pydantic import BaseModel, constr class MyPydanticModel(BaseModel): name: Optional[constr(max_length=10)]