Jinja2 for PyCharm?

Viewed 1073

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?

2 Answers

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

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).

Related