在WTForms字段上设置数据属性 [英] Setting data attributes on a WTForms field
问题描述
我想将data-属性添加到表单字段以与Bootstrap集成。我在模板中尝试了以下内容:
$ $ p $ $ $ $ c $ {form.test(data-toggle =toggle,data-size = mini,data-on =是,data-off =No,type =checkbox)}}
得到这个错误:
$ p $ TemplateSyntaxError:expected token',',got'='
为什么我得到这个错误,我该如何解决?
I want to add "data-" attributes to a form field for integration with Bootstrap. I tried the following in a template:
{{ form.test(data-toggle="toggle", data-size="mini", data-on="Yes", data-off="No", type="checkbox")}}
and got this error:
TemplateSyntaxError: expected token ',', got '='
Why did I get this error and how do I fix it?
You need to use valid Python names as the variable names. Therefore names like "data-toggle" are invalid because they have a "-" in them. Change the names to use underscores, like "data_toggle". WTForms automatically converts "_" to "-" for keywords it doesn't recognize.
这篇关于在WTForms字段上设置数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!