2

I am new to both Python and Django. I am following a tutorial where the teacher is using Jinja in Visual Studio. I tried to download it from plug-ins in PyCharm, but there is nothing called Jinja.

Is there any way I can use Jinja in PyCharm? Is there any alternative?

colidyre
  • 4,170
  • 12
  • 37
  • 53
  • 1
    Does this answer your question? [Does PyCharm support Jinja2?](https://stackoverflow.com/questions/15750551/does-pycharm-support-jinja2) – colidyre Sep 12 '20 at 03:04

2 Answers2

4

Sadly, this is a PyCharm professional feature (see here).

But for the professional version and as mentioned in https://youtrack.jetbrains.com/issue/PY-1032, there is already Jinja support in PyCharm. You can set it (if not already recognized) via:

Settings/Preferences | Languages & Frameworks | Template Languages

Template Languages Settings

And optionally add other file extensions (if Jinja files are not saved as .html) in:

Settings/Preferences | Editor | File Types

File type extension settings

If you're working on Flask/Django or similar, don't forget to declare the Template Folder in:

Settings/Preferences | Project: <project name> | Project Structure

Django template folder settings

If the setup is done (it is possible that you don't have to setup anything, because everything is working out of the box), you can see that Jinja2 is detected and working, e.g.:

Live example of using Jinja

colidyre
  • 4,170
  • 12
  • 37
  • 53
  • Thank you so much for your edit and answer. But I can't see the Template Languages section in my PyCharm. Please check this: https://prnt.sc/ufvxxk –  Sep 12 '20 at 02:23
  • Ah yes, you're right. This is only for the professional version, sadly. Maybe you can get it for free, see https://www.jetbrains.com/pycharm/buy/#discounts?billing=yearly (I am not affiliated with PyCharm.)? – colidyre Sep 12 '20 at 02:33
  • ops! I may have to try Visual studio to see if they have it free. Thank you for your help though. I really appreciate it. –  Sep 12 '20 at 03:08
  • Ah! Sorry, I was not available for some time. Thank you so much for your help, Sir. –  Sep 15 '20 at 11:11
1

Just to be clear, the free version of Pycharm does actually execute Flask apps with Jinja templates and such. It's just that it can't do Jinja syntax highlighting.

Like, you'll see all your Jinja text as if it was plain HTML text when you're editing it, but then it will run it as Jinja anyways (I've used Jinja stuff such as block, extends, include, the default filter, loop.index... everything fine).

Rusca8
  • 533
  • 4
  • 11