简体   繁体   中英

How to use Bootstrap tooltips with the Python WTForms library?

I'm building a website using the (awesome) Flask framework and the WTForms plugin . I now want to use show a Bootstrap tooltip on focus of an input field ( working fiddle here ), but for this I have to give the input tag the data-toggle and title attribute as follows:

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

So I simply added them to the expression:

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

The title attribute is no problem, but the data-toggle causes a

TemplateSyntaxError: invalid syntax for function call expression

Does anybody know how I can add the data-toggle to the input field using WTForms?

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

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

or, wtform's will helpfully decode an underscore to a hyphen:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM