Pycharm suddenly not detecting ANY Django tags in template

After a recent update Pycharm has started to throw warnings for any bit of Django template code. {% load %} tags, {% if %} or {% for %} loops, static files; anything.

Everything runs fine, I just have tons of warnings in my code that aren't accurate or helpful. 

I have invalidated cache, triple-checked my INSTALLED_APPS and my settings.py in general. Again, it's working fine. Just throwing warnings that make no sense.

5

Could you please remove django-stubs? It seems to cause the problem.

4

Hi,

Well, this is not normal. Please ensure that HTML is enabled as a file type for Django templates under **File | Settings/Preferences | Languages & Frameworks | Python Template Languages**

Does the issue reproduce if you create a new minimal project and test there?

I would also suggest to back up your settings (File > Export settins), then reset all settings to default by deleting the config directory (https://intellij-support.jetbrains.com/hc/en-us/articles/206544519) and check after that. This will show us if the issue was in your settings after all. Then you can import the settings back.

3
Avatar
Permanently deleted user

I am encountering the exact same issue. My settings.py is correctly set up, project structure is as suggested, Django support is obviously enabled and points to the correct folders and files, template language is django and html files are included.

Strangely, autocompletion/suggestions for paths pointing from templates to other templates or static files work fine. The extends, include and the block tags are apparently recognized normally by PyCharm, but all other tags so far (i.e. load, if, for, static, url) are highlighted as "unresolved tag".

Currently trying out the professional version:

PyCharm 2019.1.1 (Professional Edition)
Build #PY-191.6605.12, built on April 3, 2019
Licensed to PyCharm Evaluator
Expiration date: May 27, 2019
JRE: 11.0.2+9-b159.34 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

Django support was a major argument for getting the pro version, so it would be nice if this was fixed. Any help is greatly appreciated.

2
Avatar
Permanently deleted user

Just spent my morning resetting my environment twice. Despite uninstalling Pycharm, removing all associated caches, registry keys, settings, temp data, and even deleting the .idea folder in my project, and then doing a fresh install with no imported settings; the issue remains. As soon as Pycharm loads up my project and inspects it, it is riddled with inaccurate error messages.

I uploaded my logs to the link you provided earlier. Filename is "jmiller-pycharm-logs-20190508-114029.zip"

2
Avatar
Permanently deleted user

HTML is enabled as a file type for Python Template languages for Django. Will try wiping all settings.

 

1
Avatar
Permanently deleted user

Wiped all settings as described above and the problem persists.

Is my project structure setup correctly?

1
Avatar
Permanently deleted user

Created a new Django project with a similar basic format. The issue persists.

 

Filename is "pycharm_template_inspection_issues.zip"

1
Avatar
Permanently deleted user

What @df describes is exactly my issue.

1
Avatar
Permanently deleted user

@Pavel Not sure why that would be helpful for finding the problem, but here you go:

beautifulsoup4==4.7.1                                                                                                   
certifi==2019.3.9                                                                                                       
chardet==3.0.4                                                                                                          
colorama==0.4.1                                                                                                         
dataclasses==0.6                                                                                                        
Django==2.2.1                                                                                                           
django-crispy-forms==1.7.2                                                                                              
django-filter==2.1.0                                                                                                    
django-stubs==0.12.1                                                                                                    
djangorestframework==3.9.3                                                                                              
djangorestframework-stubs==0.4.2                                                                                        
httpie==1.0.2                                                                                                           
idna==2.8                                                                                                               
multiprocessing-logging==0.2.6                                                                                          
mypy==0.701                                                                                                             
mypy-extensions==0.4.1                                                                                                  
mysql-connector-python==8.0.16                                                                                          
mysqlclient==1.4.0                                                                                                      
protobuf==3.7.1                                                                                                         
Pygments==2.3.1                                                                                                         
pytz==2019.1                                                                                                            
PyYAML==5.1                                                                                                             
requests==2.21.0                                                                                                        
selenium==3.141.0                                                                                                       
six==1.12.0                                                                                                             
soupsieve==1.9.1                                                                                                        
sqlparse==0.3.0                                                                                                         
typed-ast==1.3.5                                                                                                        
typing-extensions==3.7.2                                                                                                
urllib3==1.24.3                                                                                                         

Suffice it to say, I have of course pointed Pycharm to the correct interpreter, that being the virtual environment created using pipenv. And yes, Django is installed in that virtual environment.

Here is a screenshot:

By the way, the recent update to PyCharm did not fix the problem. Please let me know, if I should wait with buying a license until you fixed the problem since this is an important issue for me.

1

In my case, it was "Vue.js" plugin that was giving me trouble.

The solution was to add "Vue.js template" in Settings -> Languages & Frameworks -> Template Languages -> Template File Types.

1

Everything looks correct on the screenshot. Does the issue reproduce every time in every project? If yes, please create a new project with some minimal code, ensure the issue is reproduced, and upload the zipped project to our FTP so we could try and reproduce inhouse (https://uploads.services.jetbrains.com/). After uploading, let me know the file name.

If the issue is only specific to your current project, let me know.

0

@iamjonmiller

Thanks for the project. Unfortunately I can't reproduce the issue, the tags are resolved correctly for me.

Please provide log files (can be located according to https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files), your Python and Django versions.

0

Could you please provide the

pip freeze

output for the interpreter used by the project? The problem is reproducible for me while no interpreter is selected, but as soon as I point the project to the Python with Django installed it starts to resolve tags correctly.

0
Avatar
Permanently deleted user

Thank you, this actually solved the issue (for me)! Intresting, why that is though. Since I currently don't need these stubs packages, this solution is fine for the moment.

(It may be worth noting for someone with the same issue that to remove django-stubs, djangorestframework-stubs had to be removed as well due to the latter's dependency on the former.)

0
Avatar
Permanently deleted user

Thank you Pavel! I really appreciate you chasing this down. Everything is working again!

0

I have been seeing exactly the same problem for the last 3 days and have gone through reinstallation and all manner of attempts to try and track it down.I don't know when it started to appear - possibly when I moved from Python 3.6 to 3.7 or maybe when upgrading to PyCharm 2019.1.3.

Along the way I noticed that if I changed the template language to Jinja2, the errors disappeared, but was not 100% happy with that as a solution.

Removing django-stubs and djangorestframework-stubs fixed it for me too!

 

 

0
Avatar
Permanently deleted user

I am experiencing this as well and I have tried all the settings things as described. Do you see anything that would break this functionality in this pip freeze?

 

(virtualenv) jebsky@theSeed ~/web/yogijeffrey $ pip freeze
beautifulsoup4==4.7.1
bleach==3.1.0
braintree==3.40.0
certifi==2018.1.18
cffi==1.12.1
chardet==3.0.4
cssutils==1.0.2
Django==1.11.7
django-appconf==1.0.2
django-compressor==2.2
django-inlinecss==0.2.0
django-naomi==0.8
eyeD3==0.8.9
future==0.17.1
html5lib==1.0.1
idna==2.6
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
olefile==0.44
Pillow==4.3.0
pycparser==2.19
pydub==0.23.1
pynliner==0.8.0
python-magic==0.4.15
pytz==2017.3
rcssmin==1.0.6
requests==2.18.4
rjsmin==1.0.12
six==1.12.0
soupsieve==1.9.1
urllib3==1.22
webencodings==0.5.1
Werkzeug==0.14.1

0

Hi Jeb16, could you please create a ticket in PyCharm's bug tracker and provide more details about where and which exact warnings are shown?

0

I had the exact same issue, and it solved it removing djangorestframework-stubs & django-stubs as @Pavel mentioned.

Is there any way to fix the bugs with these packages installed?

0

Hi,

I have latest Pycharm 2019.2 professional version. Ubuntu 18 LTS, python 3.7

I dont have djangorestframework-stubs & django-stubs in my virtual env or global system. I still have the same issue.

Some one on stackoverflow suggested this - https://stackoverflow.com/a/22892150/3842788 but that generates error when deploying on google app engine.

Pycharm has cost me a lot of time for configuration and bug fixes.

0

I can confirm that removing django-stubs has fixed the issue.

Is this a problem with Pycharm or django-stubs is missing stubs?

0

Try PyCharm 2019.3 EAP version. With PY-36265 in place the problem should be obsolete.

0

I am also having the problem with the PyCharm showing {{tags}}

PyCharm 2020.2.3 (Community Edition)
Build #PC-202.7660.27, built on October 6, 2020
Runtime version: 1.8.0_261-b12
VM: Java HotSpot(TM) Server VM by Oracle Corporation
Linux 4.15.0-121-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 2035M (showing but I have 5GB installed on my system...? )
Cores: 2

Current Desktop: Linux Ubuntu 18.04 LTS for i386

Python 3.6.5

Django == 3.0.1

Running on VirtualEnv

 

So this is base.html in the TEMPLATES folder (configured the settings as should)

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Coding for Boris Milanovic is going Full Stack</title>
</head>
<body>
{% include 'navbar.html' %}

{%block content%}

<p>replace me </p>

{% endblock content %}

</body>
</html>

and now from base.html everyone inherits and that's OK, but

This is about.html:

{% extends "base.html" %}

{% block content %}
<h1>About</h1>
<p1>This is a template</p1>


<p>
{{ my_text }}, {{my_number}}
{{ my_list }}
</p>

<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>


{% endblock content %}


It doesn't show the context tags from views.py:

from django.http import HttpResponse
from django.shortcuts import render



# Create your views here.


def home_view(request, *args, **kwargs):
return render(request, "home.html", {})


def contact_view(request, *args, **kwargs):
return render(request, "contact.html", {})


def about_view(request, my_context):
my_context = {
"my_text": "This is about us",
"my_number": 123

}
return render(request, 'about.html', my_context)


def social_view(request, *args, **kwargs):
return render(request, "social.html", {})

It was working...In another project but as soon as I've updated it is like this...

Here's the modules installed:

 

I have added these "wheezy" things and djangorestframework, django-rest-framework, and HTSQL, HTSQL_DJANGO to see if it will help - nope...

Please help!!!!

I cannot finish learning Python and Django... :(

0

Milanovicful

Hi,

You mentioned you're using Community version, which doesn't support Django, so tags won't be resolved.

Do you see any error?

0

I have to say that, that is simply not true. In another tutorial just a day before, I was able to use tags. What happened... Does it have to do with update?

0

You can use tags, but they won't be resolved by code insight, and won't be highlighted.

Could you provide more information about your issue? Screenshot would help.

0

I know that Pro version offers Special Support, but when I was following that tutorial {{ }} tags were appearing. Now when I switched to some other which works on django2.x instead of 3.x they all the sudden do not appear. I dont think I have screenshots but I will check, as I am the phone right now, tomorrow by UTC+1 (Belgrade, Europe) time. I will follow again the tutorial where they show up the {{tag}} which should displaye context of def...Question (request) :
'tag': 'sometext'

Return render(...'page.html',context...)
And Base. Html for instance{% includes Base.html %} is working but when I try to get context at {{ item from the context list1}}, {{... item from the context list 2}} tags it display only the "," sign...

While following previous tutorial (this one is trydjango with installed 3.0.1 django and Python 3.6.5 and doesnt work, while I was following tutorial from Mr. Parwitz I did fine..

😢😢😪

0

This problem still exists on PyCharm 2022.2.1. As a paying subscriber for over 3 years, silly unresolved problems like these have me considering VS Code more and more. Removing django-stubs package fixes. Why can't JetBrains handle this? Annoying. 

 

0

I have the same problem with 2022.2.2 - suddenly stopped parsing django templates correctly. Funnily, the problem is visible in django's own files (in my django env's `contrib/admin/templates/admin/edit_inline/tabular.html`), as where my own projects' .html files are unaffected.

0

I just solved the problem, 

When loaders are set, APP_DIRS needs to be set to False,
But Setting APP_DIRS to False causes PyCharm to fail to resolve the tag, 

Comment out loads,and APP_DIRS set True, Problem solved!

TEMPLATES = [
{
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
"BACKEND": "django.template.backends.django.DjangoTemplates",
# https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
"DIRS": [str(APPS_DIR / "templates")],
# 设置了loaders,需要將APP_DIRS設置爲False, 但会导致Pycharm不能解析标签
"APP_DIRS": True,
"OPTIONS": {
# https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
# "loaders": [
# "django.template.loaders.filesystem.Loader",
# "django.template.loaders.app_directories.Loader",
# ],
# https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"kbase.utils.context_processors.settings_context",
],
},
}
]

 

-1

请先登录再写评论。