开发者

Django Template For Loop Removing <img> Self-Closing

开发者 https://www.devze.com 2022-12-20 19:20 出处:网络
Django\'s for loop seems to be removing all of my <img> tag\'s self-closing...ness (/>). In the Template, I have this code:

Django's for loop seems to be removing all of my <img> tag's self-closing...ness (/>). In the Template, I have this code:

{% for item in item_list %}
<li>
    <a class="left" href="{{ item.url }}">{{ item.name }}</a>
    <a class="right" href="{{ item.url }}">
        <img src="{{ item.icon.url }}" alt="{{ item.name }} Logo." />
    </a>
</li>
{% endfor %}

It outputs this:

<li>
    <a class="left" href="/some-url/">This is an item</a>
    <a class="right" href="/some-url/">
        <img src="/media/img/some-item.jpg" alt="This is an item Logo.">
    </a>
</li>

As you can see, the <img> tag is no longer closed, and thus the page doesn't validate. This isn't a huge issue since it'll still render properly in all browsers, but I'd like to know how to solve it. I've tried wrapping the whole for loop in {% autoescape off %}...{% endautoescape %} but that didn't change anything. All other self-closed <img> tags in the document outside the for loop still properly clos开发者_如何学编程e.


Django's template engine is not capable of making this change. Are you sure this is the code you see when you do View Source?

0

精彩评论

暂无评论...
验证码 换一张
取 消