我的基本模板是爲什麼django在擴展後生成空字符串?
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}My amazing site{% endblock %}</title>
</head>
<body>
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog/">Blog</a></li>
</ul>
{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
索引頁:
{% extends "base.html" %}
{% block title %}My amazing blog{% endblock %}
{% block content %}
{% for entry in blog_entries %}
<h2>{{ entry.title }}</h2>
<p>{{ entry.body }}</p>
{% endfor %}
{% endblock %}
什麼是錯的,爲什麼它是產生這些引號內的怪空的文本? 它影響我的佈局。你有什麼想法?謝謝。你的標題標籤插入身體標記
我注意到,但模板代碼似乎是正確的。 – 2012-02-25 18:40:52
您確定模板index.html擴展了base.html嗎? – greg 2012-02-26 12:43:48
是的,只有兩個文件,並從這兩個文件合併得到的html。 – 2012-02-26 19:22:45