Skip to content Skip to sidebar Skip to footer

Error Using Tooltips With Jinja2

I'm having a problem with Jinja2 when I try to use tooltips with a text input filed: 'invalid syntax for function call expression'. This is my code: {{ Wformulario.WCPO_Nro_Part(cl

Solution 1:

When calling a function with keyword arguments, you can only use valid identifiers for keywords; these identifiers can not use - as that is the subtraction operator. data-container is not a valid identifier.

I am assuming that you are using WTForms here to produce your inputs. In that case you can replace data- with data_ and WTForms will render these attributes correctly using a dash instead of the underscore:

{{ Wformulario.WCPO_Nro_Part(class="form-control input-sm inteiro tooltips", 
                             data_container="body", data_placement="bottom", 
                             data_original_title="Informe o Numero de Participantes: 0 a 99",
                             tabindex="3") }}

Note that only the first_ is replaced, so this creates:

<input class="form-controlinput-sminteirotooltips"data-container="body"data-placement="bottom"data-original_title="Informe o Numero de Participantes: 0 a 99"> </input>

Note the _ in original_title.

To work around that you'd have to pass in the information in a dictionary instead, and use ** (double-splat) call instead:

{{ Wformulario.WCPO_Nro_Part(class="form-control input-sm inteiro tooltips", 
                             data_container="body", data_placement="bottom", 
                             tabindex="3",
                             **{'data-original-title': "Informe o Numero de Participantes: 0 a 99"}) }}

Now the data-original-title argument is being passed in not as a keyword argument but as part of a dictionary.

Post a Comment for "Error Using Tooltips With Jinja2"