【发布时间】:2015-06-22 21:20:09
【问题描述】:
我正在使用 django 模板来呈现我的网页。在展开递归树的过程中发生了一些奇怪的事情(并且无空格标记没有帮助)。
这是我的递归模板:
index.html:
<ul class="Container">
<li class="IsRoot">
<div class="Expand">
</div>
<div class="Content">
Содержание
</div>
</li>
{% include 'list.html' with data=list %}
</ul>
和list.html(作为递归部分):
<ul class="Container">
<li class="Node ExpandClosed">
<div class="Expand"></div>
<div class="Content">
<a href="/help/{{data.name}}">
{{data.content}}
</a>
</div>
{% for item in data.decendent %}
{% include 'list.html' with data=item %}
{% endfor %}
</li>
</ul>
结果如下:
使用 open("index.html", 'r').read() 作为 html-file 内容读取的文件的 html 内容被提取为文本,而不是 html:
<div id="frame" style="float:left; margin-left:310px;">
<!DOCTYPE html>
<html>
<head>
<title>hello</title>
</head>
<body>
Body Great Style
</body>
</html>
</div>
而且我在元素之间还有奇怪的空格:
如何避免这种奇怪的行为?谢谢!
【问题讨论】:
标签: python html django django-templates