gpt4 book ai didi

validation - Flask-WTF : How to allow zero upon DataRequired() validation

转载 作者:行者123 更新时间:2023-12-03 15:37:35 24 4
gpt4 key购买 nike

我已经定义了这样的形式:

class RecordForm(Form):
rating = IntegerField('Rating')

如果未插入任何值,则会显示如下默认消息:
Not a valid integer value

我想有一个自定义消息,所以我想到了这个:
class RecordForm(Form):
rating = IntegerField('Rating',[validators.DataRequired("Helllo???")])

自定义消息现在可以使用,但是有副作用。 0(零)不再被接受为整数值。请问我在这里有什么选择?

最佳答案

使用 InputRequired 代替:

class RecordForm(Form):
rating = IntegerField('Rating',[validators.InputRequired("You got to enter some rating!")])

从文档中:

Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired looks at the post-coercion data.



(强调我的)

关于validation - Flask-WTF : How to allow zero upon DataRequired() validation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17041787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com