本文整理汇总了Python中django.core.exceptions.ValidationError.schema方法的典型用法代码示例。如果您正苦于以下问题:Python ValidationError.schema方法的具体用法?Python ValidationError.schema怎么用?Python ValidationError.schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.exceptions.ValidationError
的用法示例。
在下文中一共展示了ValidationError.schema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from django.core.exceptions import ValidationError [as 别名]
# 或者: from django.core.exceptions.ValidationError import schema [as 别名]
def validate(data, schema):
"""
Validates the data against given schema and checks validity of ds_id and ds_spirit.
:param data: The data to validate
:param schema: The JSON schema to use for validation.
:return: Valid data
"""
if isinstance(data, dict):
properties = data
elif isinstance(data, Individual):
properties = data.properties
else:
raise ValidationError(
"An Individual can only work with a dict as data and got {} instead".format(type(data))
)
if "_id" in properties:
del properties["_id"]
try:
jsonschema.validate(properties, schema)
except SchemaValidationError as exc:
django_exception = ValidationError(exc.message)
django_exception.schema = exc.schema
raise django_exception