擅长:python、mysql、java
<p>在<strong>WTForms 2.1</strong>中,我使用<code>extra_classes</code>,如下面的行:</p>
<p><strong>1。第一条路</strong></p>
<pre><code>{{ f.render_form_field(form.first_name, extra_classes='ourClasses') }}
</code></pre>
<p>或者你的情况是这样的:</p>
<pre><code>{{ form.first_name, extra_classes='ourClasses' }}
</code></pre>
<p>我们还可以对表单字段使用<code>render_kw</code>属性,如下所示:</p>
<p><strong>2。第二条路</strong></p>
<pre><code>style={'class': 'ourClasses', 'style': 'width:50%; other_css_style;'}
first_name = StringField('First name',
validators=[InputRequired(),Length(1, 64)],
render_kw=style)
</code></pre>
<p>但我更愿意用第一种方式。</p>