I noticed that when i input a link into for loop in my templates that it gets injected into the first, lower elements. Il illustrate it below:
Base template:
<html>
<head></head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
template which extends Base template
{% extends 'base.html'%}
{% block content %}
{% if elem_list %}
<ul>
{for elem in elem_list}
<li> <a class="bob" href="">
<div class="div1">
<div class="subdiv"></div>
</div>
<div class="div2">
<div class="subdiv"></div>
</div>
</a> </li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
and the output i get on my page
<html>
<head></head>
<body>
<ul>
<a class="bob" href="">
<li> <a class="bob" href="">
<div class="div1">
<a class="bob" href=""></a>
<div class="subdiv"><a class="bob" href=""></a></div>
<div class="subdiv"></div>
</div>
<div class="div2">
<a class="bob" href=""></a>
<div class="subdiv"><a class="bob" href=""></a></div>
<div class="subdiv"></div>
</div>
</a></li>
</ul>
</body>
</html>
Is this some kind of feature Django has? How can i stop it?
答案 0 :(得分:2)
这与Django毫无关系。
您的HTML无效,因为像a
这样的内联元素不能包含像div
这样的块元素。
您可能是通过浏览器的开发者工具查看生成的HTML,这些工具正在尽最大努力解释您的HTML。