Add a css class to a field in wtform

后端 未结 4 2272
醉梦人生
醉梦人生 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:46

    If you would like to programatically include the css class (or indeed, any other attributes) to the form field, then you can use the render_kw argument.

    eg:

    r_field = RadioField(
        'Label', 
        choices=[(1,'Enabled'),(0,'Disabled')], 
        render_kw={'class':'myclass','style':'font-size:150%'}
    )
    

    will render as:

提交回复
热议问题