Validation¶
-
schematics.validate.
validate
(cls, instance_or_dict, partial=False, strict=False, context=None)¶ Validate some untrusted data using a model. Trusted data can be passed in the context parameter.
Parameters: - cls – The model class to use as source for validation. If given an instance, will also run instance-level validators on the data.
- instance_or_dict – A
dict
ordict
-like structure for incoming data. - partial – Allow partial data to validate; useful for PATCH requests.
Essentially drops the
required=True
arguments from field definitions. Default: False - strict – Complain about unrecognized keys. Default: False
- context – A
dict
-like structure that may contain already validated data.
Returns: data data dict contains the valid raw_data plus the context data. If errors are found, they are raised as a ValidationError with a list of errors attached.
Usage¶
To learn more about how Validation is used, visit Using Validation