Does PyCharm support Jinja2?

42,359

Solution 1

In the pro edition, these template languages:

  • Jinja2
  • Django
  • Mako

are supported. You can configure the template language in the project's settings:

In Python Template Settings the template langauge is set to Jinja2

The community edition may lack certain template languages.

Solution 2

I think it's worth to mention that PyCharm Community edition does not support Jinja2, Mako and Django. It's available only in PyCharm Professional.

See comparison of the two.

Solution 3

enter image description here Yes pro edition from pycharm does support Jinja2 to enable it go here

From File open Settings and search for python template under Languages & Frameworks Select Python Template Languages from there Click HTML And Select Jinja2 as Template Language.

please see the image for better understanding.

Solution 4

If you are using .jinja extension instead of .jinja2, it won't work, templates are not highlighted.

You have to add the file extension to the filetypes section.

  • Preferences > General > Filetypes
  • Scroll to Jinja 2 Template
  • Register new pattern by clicking +, add *.jinja

enter image description here

Share:
42,359

Related videos on Youtube

k0pernikus
Author by

k0pernikus

I am Philipp Kretzschmar, a backend developer from Hamburg working at Demvsystem. You can find me on github. Or twitter. My main weapons of choice are: php TypeScript (I don't want to write plain JavaScript anymore) and nodejs I play around with: Java python rust I used to write some scala, but for now I don't want to go there anymore. I feel most comfortable on a unix-like system featuring a powerful bash. (This excludes MacOS.) I love to code within JetBrains's flavored IDEs, e.g. IntelliJ, PhpStorm, WebStorm and using the IdeaVim plugin and having a docker-compose stack to develop on.

Updated on July 05, 2022

Comments

  • k0pernikus
    k0pernikus almost 2 years

    A bottle project of mine uses Jinja2. PyCharm does not automatically recognize it and shows such lines as errors. Is there a way to make Jinja2 work?

  • Kenji Noguchi
    Kenji Noguchi over 10 years
    I got "Expected }}" warning for every function calls such as {{ func('hello word') }}. How can I fix it?
  • okigan
    okigan over 10 years
    Also worth to mention that (even as of PyCharm 3.1) Debugging Jinja and Mako templates is not supported [even in pro edition]. jetbrains.com/pycharm/webhelp/debugging-django-templates.htm‌​l
  • Spooner
    Spooner about 9 years
    You need to apply the change, otherwise it will go back to assuming django formatting.
  • Chris Mueller
    Chris Mueller about 8 years
    This is very worth mentioning. I just spent 5 minutes looking through the project settings (based on the first answer) before I read this answer.
  • Noumenon
    Noumenon about 8 years
    "Out of the box" is not correct for PyCharm Community edition -- see below. (I tried to edit this information into the answer, but it got rejected 3-2.)
  • k0pernikus
    k0pernikus about 8 years
    @Noumenon I've added the information to my own answer, as I think that clarifies it a bit more. The reject was, in principle, fine by stackoverflow standard (changes intent of the author) and edits are not necessarily there to correct false answers, for that one should either downvote the answer and create your own and write a comment. Yours was an edge-case as I do think it would have improved my answer significantly.
  • Noumenon
    Noumenon about 8 years
    Your comment would have made a great, educational rejection message for my edit. "Doesn't improve the answer even a little" tends to get my hackles up. Thank you.
  • k0pernikus
    k0pernikus over 7 years
    I am a bit confused as to where the difference is from my answer: stackoverflow.com/questions/15750551/…
  • Semicolon
    Semicolon over 7 years
    @k0pernikus this is the dark theme answer :)
  • José Tomás Tocino
    José Tomás Tocino over 7 years
    This has newbie-friendly steps, plus one for that!
  • Harrichael
    Harrichael almost 7 years
    This answer is the one that helped me, because of newbie friendly steps.
  • Ayyoub
    Ayyoub almost 7 years
    thanks guys, anything to give back for this awesome community. ! . :)
  • Jean-Marc Amon
    Jean-Marc Amon over 5 years
    Thanks,it's helps me a lot
  • t3chb0t
    t3chb0t over 2 years
    I use the jinja2 extension but this doesn't seem to play along with the template settings that only allow to pick html. Should I use html or jinja2 as extensions in order for the preview to work?
  • Telemat
    Telemat over 2 years
    Thanks a bunch!