Jinja2 JSON templates not being recognised by templates
Answered
I have a number of Jinja2 templates that output JSON. The directory they are in is marked as a template directory in the Project Structure settings. I have Jinja2 selected as the template language in Python Template Languages, and I've added JSON as a template file type in that section. However when I open a template, it's being parsed as plain JSON, not a template. This means that constructs like the following are flagged as syntax errors:
{
"someKey": {{someObject|tojson}}
}
I can't seem to find any way to get these Jinja2 templates to be actually parsed as templates. How do I do this?
Please sign in to leave a comment.
Hello Jim.
In "File | Settings | Editor | File Types" remove ".json" from JSON file type and add it to Jinja2 file type. It will disable JSON highlighting by enable Jinja2.
There is no way to support both Jinja2 and JSON and one file (only html+Jinja2 is supported) but I created feature request: https://youtrack.jetbrains.com/issue/PY-24246
You can vote for it.
Hello.
Do you use ``.json`` extension?
Yes.