2

I am making my first steps at flask, I'm trying to make custom html tags with wtf-forms

when i use this:

{{form.email(data-trigger="hover")}}

i got this:

jinja2.exceptions.TemplateSyntaxError: expected token ',', got '='

without it everything works:

{{form.email(datatrigger="hover")}}

is there any way to fix it?

novox
  • 143
  • 1
  • 10
  • 1
    This is a duplicate of [http://stackoverflow.com/questions/27779024/setting-data-attributes-on-a-wtforms-field](http://stackoverflow.com/questions/27779024/setting-data-attributes-on-a-wtforms-field) – dirn Feb 22 '15 at 00:03

1 Answers1

6

Identifiers in Python (including Python snippets embedded in Jinja2) can include letters, underscores, and digits (and can't start with a digit).

Other punctuation, including dashes, are not allowed in identifiers (not a Python peculiarity -- many other languages have exactly the same lexical rules for what's allowed in an identifier).

So no, there is no way to "fix" Python to allow you to include a dash (which Python takes as a "minus" operator) within an identifier. Why would you need to? Can't you use, e.g, an underscore instead?

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • 2
    In this instance, underscores can be used as WTForms will convert the underscore to a hyphen when rendering the `input` tag. `form.email(data_trigger='...')` will become ``. – dirn Feb 22 '15 at 00:06
  • thank you alot, it works! i think i need to read documentation more accurate – novox Feb 22 '15 at 00:26