Pycharm not recognizing django template tags

I had to reinstall my mac osx and on installed a fresh copy of pycharm. I cloned a git django project and I loaded the project using open directory and it didn't recognize it. Then I ticked enable django support and everything works, I can run and stuff, except that the IDE is not recognizing my template tags such as {% for ... %} and it is not creating the closing brackets automatically. Further, the syntax highlight for the template tags are not working as well.

Any solutions?

17 comments
Comment actions Permalink

Please make sure that the Django template format is selected under Settings | Template Languages.

1
Comment actions Permalink

I'm having the same problem and my Template Language is set to Django.

0
Comment actions Permalink

Ralph,

Could you please attach a screenshot demonstrating the problem?

0
Comment actions Permalink

no template highlighting.tiff

Attached screen shot show template settings and template file open in editor. Highlighting not being applied.



Attachment(s):
no template highlighting.tiff
0
Comment actions Permalink

I'm sure it's got something to do with the .idea directory.

I tried everything, even opening my other django project that has everything working and setting the exact same settings. It still doesn't work. So in the end I deleted the default .idea directory and copied over the .idea from the django project that was working. I opened up the project, a few errors popped up and after that everything was working fine.

0
Comment actions Permalink

Please map the .djt extension to the HTML file type in Settings | FIle Types.

0
Comment actions Permalink

Problem solved. Thanks!

0
Comment actions Permalink

I have the exact same problem. My Template Language is set to Django and I've mapped the *.djt extensions to the HTML file type in Settings | File Types. Still, no template tags are being highlighted. What's more, line comment or code formatting are not working in my HTML files. 

0
Comment actions Permalink

@Martyszek

Please provide screenshots to demonstrate the issue and **idea.log** file, which you can find using **Help > Show log in...** action.

Ensure that you have HTML Tools plugin enabled.

0
Comment actions Permalink

Hi i have the same problem, i've checked that html plugin is enabled and in the settings there is an extension *.djt, but the problem isn't solved. I attached a screenshot.

0
Comment actions Permalink

Template tags are not recognized, please notice also the changed icon of the .html file. I've done all of the above, nothing seemed to be the case.

0
Comment actions Permalink

Do you have Vue.js plugin installed?
There is a known issue with it https://youtrack.jetbrains.com/issue/PY-41619

2
Comment actions Permalink

If Vue.js plugin installed

Add Vue.js template in Settings | Languages & Frameworks | Template Languages | Template File Types it's fix Django template support

9
Comment actions Permalink

axel thanks a lot! it was bugging me for a long time

0
Comment actions Permalink

axel you saved my day and my year !

0
Comment actions Permalink

Custom Template Tags and Inheritage| Loops and Ifs/ Else

 

My issue was the same, just I wasn't careful when I was setting up the settings.py in templates the DIR:[ ] has to show on 'templates' (folder inside the app), or the path of it 'absolute path', as well as I haven't pay the attention on context rendering and hmtl tags inside of base.html file.

So finally I got the {{list}} and {{my_num}} working by configuring it like this:

def News(request):


context = {
"list":["Python", "Java", "C++", "Kotlin","Ruby"],
"my_num": 500
}


 

And

{% extends 'base.html' %}

{% block title %} News {% endblock %}
{% block body %}

<h1>This is our latest news page</h1>


<p>This is our latest news description</p>

{{list}}

{% for lang in list %}

<ul>
<li>{{ lang }}</li>
</ul>

{% endfor %}



{% if my_num == 50 %}

<h1> Condition is true</h1>



{% else %}
<h1> Condition is false</h1>

{% endif %}

{% endblock %}

 

 

So basic example that PRACTICE and PAYING ATTENTION ON THE SMALLEST DETAILS CAN occur in issue while rendering your pages/templates and template custom tags/tags.

 

Thank you all, and PyCharm Community and Intellij-support/ jetbrains.com @Andrey Leisler Axel, Nicolas Devaux Sergey Karpov and zentenk1(for pulling out this 'charming' topic) it's been a 100... :)

One Feature Request (as I worked as DevOps in one huge reputable enterprise company):

 

  • Please even in the community edition, you could at least make it automatically {% to show the closure " %}" so it would be much easier to program and not waist seconds and stuff on {% some text %}  as it in fast-typing it can easily occur that it can end up like this %{some text%} or even with {{ }} context tags...
0

Please sign in to leave a comment.