Why is VS Code showing an error when I use a jinja2 for loop inside javascript?

Viewed 866

I am using Flask do develop a web app to visualize data retrieved from a database. I want to include a chart which requires a Jinja for loop to accomplish population of the chart. When I place the for loop inside the JavaScript <script> tag in an .html document VS Code shows a syntax error. It's fine outside the <script> tag. I tried the exact same code in Eclipse and receive no formatting error. I have also noticed that Jinja text tags such as '{{label}}' can be entered inside JavaScript with no syntax error showing.

screen shot of syntax error in VS Code

I have spent a lot of development time in VS Code and would prefer to not have to switch IDEs at this stage. Any help would be greatly appreciated.

1 Answers

After a bit of experimenting I found the Python Extension Pack by Don Jayamanne. It solved the syntax error problem. I still get some strange color coding, but everything seems to be working. If anyone has a suggestion of a better extension pack, I would love to give it a try.

Related