I want to add "data-" attributes to a form field for integration with Bootstrap. I tried the following in a template:
{{ form.test(data-toggle="toggle", data-size="mini", data-on="Yes", data-off="No", type="checkbox")}}
and got this error:
TemplateSyntaxError: expected token ',', got '='
Why did I get this error and how do I fix it?
WTF stands for WT Forms which is intended to provide the interactive user interface for the user. The WTF is a built-in module of the flask which provides an alternative way of designing forms in the flask web applications.
The FlaskForm base class is defined by the Flask-WTF extension, so it is imported from flask_wtf . The fields and validators, however, are imported directly from the WTForms package. The list of standard HTML fields supported by WTForms is shown in Table 4-1. Table 4-1. WTForms standard HTML fields.
StringField (default field arguments)[source] This field is the base for most of the more complicated fields, and represents an <input type="text"> .
If you want to add an attribute like "disabled" or "readonly" then you can do it like this
{{ form.test(class_="input", readonly="readonly") }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With