Syntax Highlighting Python Code on HTML in VSCode

--

If we’re talking about Python code in HTML script, we’re definitely talking about a web framework whether it’s using Flask or Django with Jinja2 templates.

Syntax highlighting in Python code will not be active when we type in the HTML script.

In order for syntax highlighting in Python code to be active, we need to do the following steps.

  1. Install Better Jinja plugin (https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml).
  2. Go to Preferences ⮞ Settings ⮞ type “File Associations” in the search settings bar, click on “edit settings.json”.
  3. Add this following lines of code before close curly braces, then save it.
    "emmet.includeLanguages": {"jinja-html": "html"},
    "files.associations": {
    "*.html": "jinja-html"
    }
  4. Walaaa!

--

--