How do I use Bootstrap tooltips with the Python WTForms library?

I am creating a website using (awesome) flash framework and WTForms Plugin . Now I want to use Bootstrap show prompt on the focus of the input field ( working fiddle here ), but for that I have to give the input tag an attribute data-toggle

and title

like this:

<input data-toggle="tooltip" title="tooltip on focus!" type="text" placeholder="Focus me!" name="thename"/>

      

So I just added them to the expression:

{{ form.plotting_value(title='tooltip on focus!', data-toggle='tooltip', class='form-control') }}

      

The attribute is title

not a problem, but it data-toggle

causes

TemplateSyntaxError: Invalid function expression syntax

Does anyone know how I can add data-toggle

to an input field using WTForms?

+3


source to share


1 answer


Python doesn't like hyphens, you can either give it a dictionary:

{{ form.example(**{'data-toggle': 'tooltip'}) }}

      



or, wtform will help you decode the underscore to a hyphen:

{{ form.example(data_toggle: 'tooltip') }}

      

+4


source







All Articles