更新时间:2021-11-01 09:58:12
我在此页的 BaseSerializer部分中,有一个示例显示ValidationError可以在初始化时采用字典参数。
I figured it out, on this page of the documentation in the "BaseSerializer" section, there's an example that shows ValidationError can take a dictionary argument upon initialization.
如果我 raise ValidationError({'field_val1':['此字段无效']})
得到我想要的JSON响应。
If I raise ValidationError({'field_val1': ['this field is not valid']})
I get the JSON response I want.