flask-wtf 字段渲染示例

1 投票
1 回答
741 浏览
提问于 2025-04-17 13:57

我在比较wtforms的字段(可以理解为表单中的输入项)和普通的<input>标签。对于wtforms中的一些字段,它们对应的<input type>类型很容易猜到,但对于其他一些字段,我就不知道它们应该怎么实现了。

有没有什么示例网页可以让我试试渲染出来的wtform字段?或者有没有一些wtforms的模板集合,让我可以自己动手试试?

1 个回答

1

你可以通过查看源代码轻松找到答案:

# ... snip ...
class SearchField(core.StringField):
    """
    Represents an ``<input type="search">``.
    """
    widget = widgets.SearchInput()


class TelField(core.StringField):
    """
    Represents an ``<input type="tel">``.
    """
    widget = widgets.TelInput()


class URLField(core.StringField):
    """
    Represents an ``<input type="url">``.
    """
    widget = widgets.URLInput()
# ... snip ...

撰写回答