Can't figure out why PyCharm is giving me this "Tag start is not closed" error on this Django template
I have the following code in an HTML template...
<table id="{{ table_id }}"
{% if table_css_classes %}class="{{ table_css_classes }}"{% endif %}
{% if table_attrs %}{% for key, val in table_attrs.items %}{{ key }}="{{ val }}"{% endfor %}{% endif %}>
</table>
PyCharm is putting a red squiggle error line under the first `{` of the closing `endif` tag right after `class="{{ table_css_classes }}"` with the error message "Tag start is not closed" (see screenshots). Rendering the template works fine, and I don't see anything semantically wrong, so I'm not sure why PyCharm is raising this error, and I'm not seeing any way to suppress it.


The issue is the same if I put the entire tag on one line, and every other line break combination I've tried.
I'm on Windows 10 using PyCharm Pro 2022.3.1 Build #PY-223.8214.51. I already have Django support enabled. I have many other templates in this project, and no other template issues that I'm aware of. I've already tried updating and restarting PyCharm, but that did not work.
EDIT: Looks like maybe it's the variable as an attribute name that's throwing it off? I added the following code and got the same exact issue...
<thead id="{{ thead_id }}"{% for key, val in thead_attrs.items %} {{ key }}="{{ val }}"{% endfor %}>
</thead>
Like, if it sees `something="{{ variable }}"` it knows that the tag is still going because it recognizes that as an HTML attribute, but if it sees {{ variable1 }}="{{ variable2 }}" it doesn't recognize that as an attribute and just thinks you forgot to close the tag?
请先登录再写评论。
Could be related https://youtrack.jetbrains.com/issue/PY-55299/PyCharm-incorrectly-believes-HTML-tags-are-not-closed-if-a-jinja2-for-block-is-used-to-set-element-attributes-inside-the-tag
Seems that some improvement for tag handling is needed.
Yeah, looks like the same exact issue. For what it's worth, I don't think it's the `{% for %}` tag that causes the issue as the title of that post suggests. If I do...
<thead id="{{ thead_id }}"{% for i in '123'|make_list %} data-test="whatever"{% endfor %}><thead id="{{ thead_id }}"{% for i in '123'|make_list %} data-{{ i }}="whatever"{% endfor %}><thead id="{{ thead_id }}"{% include './_attrs.html' with attrs=thead_attrs %}>{% for key, val in attrs.items %} {{ key }}="{{ val }}"{% endfor %}I've noticed several similar “false alerts” as visible hereafter:
They are all related to additional parameters in the tags.
My current version of PyCharm as reported in the About box is :
It looks like a different problem. Please create an issue on YouTrack so we can properly process it: https://youtrack.jetbrains.com/issues/PY