【发布时间】:2020-08-28 03:33:18
【问题描述】:
我需要更改验证字段时显示的错误的视图。
serializer.py
class ElementCommonInfoSerializer(serializers.ModelSerializer):
self_description = serializers.CharField(required=False, allow_null=True,
validators=[RegexValidator(regex=r'^[a-zA-Z0-9,.!? -/*()]*$',
message='The system detected that the data is not in English. '
'Please correct the error and try again.')]
)
....
class Meta:
model = Elements
fields = ('self_description',......)
显示此错误
{
"self_description": [
"The system detected that the data is not in English. Please correct the error and try again."
]
}
错误字典的键是字段名-self_description。对于 FE,我需要发送另一种格式,例如:
{
"general_errors": [
"The system detected that the data is not in English. Please correct the error and try again."
]
}
如何改变这个?
【问题讨论】:
标签: django django-rest-framework django-serializer django-validation