擅长:python、mysql、java
<p>WTForms字段可以是<a href="https://wtforms.readthedocs.org/en/latest/fields.html#wtforms.fields.Field.__call__" rel="noreferrer">called</a>,其属性将在它们呈现的输入上设置。将样式设置、JavaScript功能等所需的属性传递给字段,而不仅仅是引用字段。标签的行为方式相同,可以使用<code>field.label</code>访问。</p>
<p><code>for</code>、<code>value</code>、<code>type</code>、<code>id</code>和<code>name</code>不需要传递,因为它们是自动处理的。有一些<a href="https://wtforms.readthedocs.org/en/latest/widgets.html#wtforms.widgets.html_params" rel="noreferrer">rules</a>用于处理属性的特殊情况。如果属性名是Python关键字,例如<code>class</code>,请附加下划线:<code>class_</code>。破折号不是有效的Python名称,因此单词之间的下划线将转换为破折号;<code>data_toggle</code>变为<code>data-toggle</code>。</p>
<pre><code>{{ form.first_name(class_='validate') }}
{{ form.first_name.label(class_='active') }}
{{ form.begins(class_='datepicker', length=50) }}
</code></pre>
<p>注意,两个链接的方法都不需要直接调用,这些文档只描述调用字段时的行为。</p>