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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…