【发布时间】:2019-03-05 21:36:51
【问题描述】:
我的 django 模板文件夹中有这样的代码:
base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
{% block home %} {% endblock home %}
</body>
</html>
top.html
<div id="top">
<h1>This is the navbar content</h1>
</div>
left.html
<div id="left">
<p>This is the menu content</p>
</div>
现在我想将这些模板中的每一个都包含到这样的主模板中
home.html
{% extends "myapp/base.html" %}
{% block home %}
{% include "myapp/top.html" %}
{% include "myapp/left.html" %}
{% endblock home %}
这是我在 views.py 中的渲染函数 视图.py
def home(request):
return render(request, 'myapp/home.html')
但是当我运行服务器时,'home.html' 中的 include 语句不起作用。怎么回事?
谢谢。
【问题讨论】:
标签: django django-templates include extends