Flask WTForms Integerfield类型是文本而不是数字 [英] Flask WTForms Integerfield type is text instead of number

查看:91
本文介绍了Flask WTForms Integerfield类型是文本而不是数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我尝试过的:

nrkomp = IntegerField('Number',validators=[NumberRange(min=1, max=5, message='Invalid length')])

在开发人员工具中,此表单输入具有文本类型而不是数字,我已经阅读了文档,但是找不到解决此问题的方法.

In developer tools, this form input has type text and not number, I have read the docs, but could not find a solution to this problem.

推荐答案

您可以使用wtforms html5

You can use wtforms html5 fields to get html5 input types, and html5 widgets as their associated widgets.

from wtforms import Form
from wtforms.fields import html5 as h5fields
from wtforms.widgets import html5 as h5widgets


class F(Form):

    n1 = h5fields.IntegerField("Number1")
    n2 = h5fields.IntegerField(
        "Number2", widget=h5widgets.NumberInput(min=0, max=100, step=10)
    )


for f in F():
    print(f)

<input id="n1" name="n1" step="1" type="number" value="">
<input id="n2" max="100" min="0" name="n2" step="10" type="number" value="">

这篇关于Flask WTForms Integerfield类型是文本而不是数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆