Correct escaping to use in Django templates to avoid Unterminated string literal errors in VS Code

Consider the following in a Django .html template

<button onclick="location.href='{% url 'my-route' pk %}'">

# Warns because of this -------^.......^

VS Code will warn of an unterminated string literal as it doesn't understand that inside {% %} is processed first by the template engine. It works just fine, but the VS Code warnings (complete with red highlighting) are distracting.

Any way to fix this either by escaping ' or " or changing some VS Code config?

Add Django extension for Visual Studio Code

https://marketplace.visualstudio.com/items?itemName=batisteo.vscode-django

Back to Top