WTForms fields can be called with attributes that will be set on the input that they display. Pass the attributes necessary for styling, JavaScript functionality, etc., to the fields, and not just referring to the fields. Labels behave the same and can be accessed using field.label .
for , value , type , id and name do not need to pass, because they are processed automatically. There are some rules for handling special cases of attributes. If the attribute name is a Python keyword, such as class , add an underscore: class_ . Dashes are not valid Python names, so underscores between words are converted to dashes; data_toggle becomes data-toggle .
{{ form.first_name(class_='validate') }} {{ form.first_name.label(class_='active') }} {{ form.begins(class_='datepicker', length=50) }}
Please note that none of the related methods should be called directly, these documents simply describe the behavior when calling fields.
source share