Turns out, you need to tell PyCharm you're using Django templates. It's in project setting under "python template languages".
Syntax Errors in my JS caused by Django Template tags
-
21-06-2023 - |
Pergunta
I'm using pycharm on a Django project.
In my templates, I have some embedded JS. And in a couple places, I'm using Django template tags in the JS. And that is causing PyCharm to mark all the JS after these template tags as a syntax error. I know it can't parse the template code, but there HAS to be a better option than trying to read my JS with Pycharm error annotations all over it.
Here is an example of the kind of stuff I'm talking about:
<script type="text/javascript">
details = {
'foo': 'bar',
{% if blah %}
'blah': {{ blah }},
{% endif %}
}
</script>
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow