Add a css class to a field in wtform

后端 未结 4 2288
醉梦人生
醉梦人生 2020-11-28 04:18

I\'m generating a dynamic form using wtforms (and flask). I\'d like to add some custom css classes to the fields I\'m generating, but so far I\'ve been unable to do so. Usin

4条回答
  •  天涯浪人
    2020-11-28 04:34

    In WTForms 2.1 I using extra_classes, like the line bellow:

    1. The first way

    {{ f.render_form_field(form.email, extra_classes='ourClasses') }}
    

    We can also use @John Go-Soco answers to use render_kw attribute on our form field, like this way.

    2. The second way

    style={'class': 'ourClasses', 'style': 'width:50%;'}
    email = EmailField('Email', 
                       validators=[InputRequired(), Length(1, 64), Email()],
                       render_kw=style)
    

    But I would like more prefer to use the first way.

提交回复
热议问题