首页 > 其他分享 >restframework 验证字段

restframework 验证字段

时间:2023-03-05 20:33:40浏览次数:36  
标签:验证 max invalid length restframework Ensure value valid

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

相关文章

  • Spring Security + JWT + Swagger2 登录验证一套流程小结
    SpringSecurity+JWT+Swagger2登录验证一套流程主要是三个框架的集成配置,以及各个独立的配置(主要是JWT+Security的登录验证)。流程:构建SpringBoot基本项目,......
  • DVWA 之 Insecure CAPTCHA-不安全的验证
    六、InsecureCAPTCHA-不安全的验证原理InsecureCAPTCHA意思是不安全的验证码,CAPTCHA是CompletelyAutomatedPublicTuringTesttoTellComputersandHumansApa......
  • 《强哥德巴赫猜想的计算机验证性程序》 回复
    《强哥德巴赫猜想的计算机验证性程序》      https://tieba.baidu.com/p/8286004205      回复  5楼 20楼 23楼  @思维机器  ,  ......
  • SpringBoot中使用Kaptcha实现验证码
    1.首先,我们在pom.xml文件中引入kaptcha的maven依赖。1<dependency>2<groupId>com.github.penggle</groupId>3<artifactId>kaptch......
  • 基本内置类型(验证)
    字符型被分为:char,signedchar,unsignedchar三种类型,需要注意的是char类型和signedchar类型不同。尽管字符型有三种,但是表现形式却只有两种:有符号和无符号的。类型char实......
  • 出报关,海关,验证码本地识别
             本地识别出售 联系v  备注购买验证码  ......
  • laravel require_if 日期验证
    'use_dates'=>'required|string|max:3','start_date'=>'required_if:use_dates,Yes|date_format:d/m/Y','end_date'=>'required_if:use_dates,Yes|date_format:d/......
  • 身份证号码格式验证
      具体验证方式详情见章未知乎链接。身份证号码格式验证,js代码1//效验省份证号码格式2functionIDCheck(id){3varr=newRegExp("^[1-9](\\d{5})(19|2......
  • 前端验证码实现
    实现:Sidentify.vue<template><divclass="s-canvas"><canvasid="s-canvas":width="contentWidth":height="contentHeight"></canvas></div></template>......
  • 680. 验证回文字符串 Ⅱ
    给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。示例1:输入:"aba"输出:True示例2:输入:"abca"输出:True解释:你可以删除c字符。 ......