【发布时间】:2012-09-02 05:03:18
【问题描述】:
我有一个从我的模板目录返回页面的视图,成功,没问题:
def home(request):
c = {}
return render_to_response('home.html', c, context_instance=RequestContext(request))
如果 home.html 是一个没有 extends 的简单网页,则返回正常。
但是,如果我使用包含,比如 {% extends "base.html" %},它只会返回 base.html,而不添加来自子 home.html 的内容。这可能是什么原因造成的?
home.html
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
This is the homepage.
{% endblock %}
base.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{% block content %}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
目前,这正在返回 base.html 的副本,如下所示:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
</body>
</html>
为什么不包括内容或标题栏?
【问题讨论】:
标签: python django django-templates