You need to use valid Python names as the variable names. Therefore names like "data-toggle" are invalid because they have a "-" in them. Change the names to use underscores, like "data_toggle". WTForms automatically converts "_" to "-" for keywords it doesn't recognize.
{{ form.test(data_size="mini") }}
You can also use dict unpacking to pass keyword arguments with keys that aren't valid variables.
{{ form.name(**{"data-size": "mini"}) }}
Rather than setting the attributes when rendering, you can set the default attributes for the field with render_kw
.
class ExampleForm(Form):
name = StringField(render_kw={"data-size": "mini"})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…