WTForms...html,自动对焦?
是否可以在 WTForms 内部使用 HTML5 中使用的一些新的仅限属性的属性?
例如,假设您要创建一个具有 placeholder="foo"、required 和 autofocus 属性的 TextField。在 WTForms 中这将如何完成?
在 html 中,它看起来像这样:
请注意 placeholder="foo"
在 WTForms 中很容易完成。 autofocus
和 required
因为它们没有价值,所以……嗯,据我所知,WTForms 不支持它们。
WTForms 可以支持这个吗?
Is it possible to have some of the new attribute only attributes used in HTML5, inside of WTForms?
Eg, say you want to create a TextField with placeholder="foo", required, and autofocus attributes. How would this be done in WTForms?
In html it would look like this: <input maxlength="256" name="q" value="" placeholder="foo" autofocus required>
Note that placeholder="foo"
is easily done in WTForms. autofocus
and required
, because they have no value, are .. well, as far as i've seen, not supported in WTForms.
Can WTForms support this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在昨天发布的 WTForms 1.0 中,HTML5 紧凑语法现已成为默认语法。现在你可以这样做(在 jinja 中):
请注意,在 Jinja 中,文字是
true
而不是True
但如果你要在 python 控制台中尝试这个,你将需要使用 python 文字True
来实现此目的。在 WTForms 0.6.x 中,它使用 XHTML 作为默认输出,您可以这样做,例如
这是在 XHTML 中表示布尔属性的推荐方法,并且这仍然是 100% 有效的 HTML5 并且完全等效,尽管生成的 HTML 是更详细一点。
In WTForms 1.0, released yesterday, HTML5 compact syntax is now the default. Now you can do (in jinja):
Note that in Jinja, the literal is
true
instead ofTrue
but if you were to try this in the python console you will need to use the python literalTrue
for this to work.In WTForms 0.6.x, which used XHTML as the default output, you could do e.g.
This is the recommended way for representing boolean attributes in XHTML, and this happens to still be 100% valid HTML5 and completely equivalent, though the HTML generated is a bit more verbose.
我是 WTForms 新手,但在我看来,该解决方案可以改进,而不是使用:
use :
WTForms 似乎无法正确处理 100% HTML5 的
required=false
并在 HTML 中设置 attrrequired="False"
而不是删除 attr。 WTForms 的下一版本可以对此进行改进吗?I'm new with WTForms but it seems to me that the solution could be improved instead of using :
use :
WTForms seems not to handle correctly
required=false
for 100% HTML5 and sets in the HTML an attrrequired="False"
instead of removing the attr. Could this be improved in next version of WTForms?您可能需要创建一个自定义小部件。
查看有关自定义小部件的文档。
You'll probably need to create a custom widget.
Check out the docs on custom widgets.