mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
17b5ff42c1
* renaming docs examples * tweaks
18 lines
333 B
Python
18 lines
333 B
Python
from pydantic import BaseModel, ValidationError, validator
|
|
|
|
class Model(BaseModel):
|
|
foo: str
|
|
|
|
@validator('foo')
|
|
def name_must_contain_space(cls, v):
|
|
if v != 'bar':
|
|
raise ValueError('value must be "bar"')
|
|
|
|
return v
|
|
|
|
try:
|
|
Model(foo='ber')
|
|
except ValidationError as e:
|
|
print(e.errors())
|
|
|