restframework 字段校验错误信息
Field(基类)
{
'required': _('This field is required.'),
'null': _('This field may not be null.')
}
BooleanField
{
'invalid': _('Must be a valid boolean.')
}
CharField
{
'invalid': _('Not a valid string.'),
'blank': _('This field may not be blank.'),
'max_length': _('Ensure this field has no more than {max_length} characters.'),
'min_length': _('Ensure this field has at least {min_length} characters.'),
}
EmailField
{
'invalid': _('Enter a valid email address.')
}
RegexField
{
'invalid': _('This value does not match the required pattern.')
}
SlugField
{
'invalid': _('Enter a valid "slug" consisting of letters, numbers, underscores or hyphens.'),
'invalid_unicode': _('Enter a valid "slug" consisting of Unicode letters, numbers, underscores, or hyphens.')
}
URLField
{
'invalid': _('Enter a valid URL.')
}
UUIDField
{
'invalid': _('Must be a valid UUID.'),
}
IPAddressField
{
'invalid': _('Enter a valid IPv4 or IPv6 address.'),
}
IntegerField
{
'invalid': _('A valid integer is required.'),
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
'max_string_length': _('String value too large.')
}
FloatField
{
'invalid': _('A valid number is required.'),
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
'max_string_length': _('String value too large.')
}
DecimalField
{
'invalid': _('A valid number is required.'),
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
'max_digits': _('Ensure that there are no more than {max_digits} digits in total.'),
'max_decimal_places': _('Ensure that there are no more than {max_decimal_places} decimal places.'),
'max_whole_digits': _('Ensure that there are no more than {max_whole_digits} digits before the decimal point.'),
'max_string_length': _('String value too large.')
}
DateTimeField
{
'invalid': _('Datetime has wrong format. Use one of these formats instead: {format}.'),
'date': _('Expected a datetime but got a date.'),
'make_aware': _('Invalid datetime for the timezone "{timezone}".'),
'overflow': _('Datetime value out of range.')
}
DateField
{
'invalid': _('Date has wrong format. Use one of these formats instead: {format}.'),
'datetime': _('Expected a date but got a datetime.'),
}
TimeField
{
'invalid': _('Time has wrong format. Use one of these formats instead: {format}.'),
}
DurationField
{
'invalid': _('Duration has wrong format. Use one of these formats instead: {format}.'),
'max_value': _('Ensure this value is less than or equal to {max_value}.'),
'min_value': _('Ensure this value is greater than or equal to {min_value}.'),
}
ChoiceField
{
'invalid_choice': _('"{input}" is not a valid choice.')
}
MultipleChoiceField
{
'invalid_choice': _('"{input}" is not a valid choice.'),
'not_a_list': _('Expected a list of items but got type "{input_type}".'),
'empty': _('This selection may not be empty.')
}
FilePathField
{
'invalid_choice': _('"{input}" is not a valid path choice.')
}
FileField
{
'required': _('No file was submitted.'),
'invalid': _('The submitted data was not a file. Check the encoding type on the form.'),
'no_name': _('No filename could be determined.'),
'empty': _('The submitted file is empty.'),
'max_length': _('Ensure this filename has at most {max_length} characters (it has {length}).'),
}
ImageField
{
'invalid_image': _(
'Upload a valid image. The file you uploaded was either not an image or a corrupted image.'
),
}
ListField
{
'not_a_list': _('Expected a list of items but got type "{input_type}".'),
'empty': _('This list may not be empty.'),
'min_length': _('Ensure this field has at least {min_length} elements.'),
'max_length': _('Ensure this field has no more than {max_length} elements.')
}
DictField
{
'not_a_dict': _('Expected a dictionary of items but got type "{input_type}".'),
'empty': _('This dictionary may not be empty.'),
}
JSONField
{
'invalid': _('Value must be valid JSON.')
}
ModelField
{
'max_length': _('Ensure this field has no more than {max_length} characters.'),
}
标签:验证,max,invalid,length,restframework,Ensure,value,valid
From: https://www.cnblogs.com/hyf120/p/17181542.html