WTForms ... html,自动对焦?

Lee*_*var 9 python wtforms

是否可以在WTForms内部使用HTML5中使用的一些新属性属性?

例如,假设您要使用占位符="foo",必需和自动聚焦属性创建TextField.如何在WTForms中完成?

在HTML中它看起来像这样: <input maxlength="256" name="q" value="" placeholder="foo" autofocus required>

请注意,placeholder="foo"在WTForms中很容易完成.autofocus并且required,因为它们没有价值,所以......好吧,就我所见,在WTForms中不受支持.

WTForms可以支持吗?

Cra*_*ast 24

在昨天发布的WTForms 1.0中,HTML5紧凑语法现在是默认语法.现在你可以做(​​在jinja):

{{ form.field(autofocus=true, required=true, placeholder="foo") }}
Run Code Online (Sandbox Code Playgroud)

请注意,在Jinja中,文字是true代替的,True但是如果你在python控制台中尝试这个,你将需要使用python文字True来实现.

在使用XHTML作为默认输出的WTForms 0.6.x中,您可以执行例如

{{ form.field(autofocus="autofocus", required="required", placeholder="foo" }}
Run Code Online (Sandbox Code Playgroud)

这是在XHTML中表示布尔属性的推荐方法,这恰好仍然是100%有效的HTML5并且完全等效,尽管生成的HTML有点冗长.


a p*_*erd 0

您可能需要创建一个自定义小部件。

查看有关自定义小部件的文档