Flask SelectField浮点值作为选择

时间:2017-04-25 12:01:46

标签: python flask wtforms flask-wtforms

是否可以为SelectField选项设置浮点值? 我尝试了以下方法:

class RatingForm(Form):

    ratings = [(0.5, 0.5), (1, 1), (1.5, 1.5), 
               (2, 2), (2.5, 2.5), (3, 3), (3.5, 3.5), 
               (4, 4), (4.5, 4.5), (5, 5)]

    rating = SelectField(u'Rate this movie', choices=ratings,
                         validators=[validators.required()], coerce=int)

    def validate(self):
        check_validate = super(RatingForm, self).validate()

        if not check_validate:
            return False

        return True

但是当我选择一个浮点值时,验证检查会返回false。如果我选择偶数(整数),它就可以正常工作。那么有没有办法从选择选项中获取浮点值?

0 个答案:

没有答案