-1

I'm passing a set of variables into a Flask template, and I would like to first manipulate them with Javascript. The problem is that when I use the {{ var }} syntax, Javascript isn't recognizing it. The errors look like this. The left brackets give an "Identifier or string literal or numeric literal expected" error, and the variable names give an "Expression statement is not assignment or call" error.

I use {{ var }} syntax later, within the HTML portion of the document, and when I do that they appear just fine. Also, enclosing it in quotes as I do for a different variable doesn't work either. Anyone know what the issue could be? Thanks.

ketone
  • 23
  • 4

1 Answers1

1

Jinja2 (flask's templating engine) is a preprocessor, meaning that its output is the real JS and it does not care about you're using it with HTML, JS or whatever, it only prints text.

That error you're getting is your text editor trying to help you but it's not smart enough to realize you're writing Jinja2 instead of javascript.

Edit: also, as @davidism says, you have to use jinja2 blocks.

martriay
  • 5,632
  • 3
  • 29
  • 39