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?

0
2 comments

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 %}>
...PyCharm doesn't complain. I can even do...
<thead id="{{ thead_id }}"{% for i in '123'|make_list %} data-{{ i }}="whatever"{% endfor %}>
...with no issues. But if the entire attribute name is a variable tag, then it gives the error. I'd bet a round of drinks that's the culprit. Seems like something they should fix being that Django support is one of the major selling features for Pro  ¯\_(ツ)_/¯
 
I just moved the attribute building loop to a separate template though, and that seems to be working well enough.
<thead id="{{ thead_id }}"{% include './_attrs.html' with attrs=thead_attrs %}>
With `_attrs.html` just being...
{% for key, val in attrs.items %} {{ key }}="{{ val }}"{% endfor %}
 
 
0

Please sign in to leave a comment.