Files
pydantic/docs/examples/config.py
T
Samuel Colvin f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00

23 lines
421 B
Python

from pydantic import BaseModel, ValidationError
class Model(BaseModel):
v: str
class Config:
max_anystr_length = 10
error_msg_templates = {
'value_error.any_str.max_length': 'max_length:{limit_value}',
}
try:
Model(v='x' * 20)
except ValidationError as e:
print(e)
"""
1 validation error
v
max_length:10 (type=value_error.any_str.max_length; limit_value=10)
"""