可以在母模板中添加多个块标签,每个块标签取不同的名称,格式如下,content是块标签名称
{% block content %} {% endblock content %}
1、母模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>母模板</title>
</head>
<body>
<section>
<h1>顶部导航</h1>
<p>顶部内容</p>
<hr>
</section>
{% block content %}{% endblock content %}
{% block abc %}{% endblock abc %}
<section>
<hr>
<h1>底部</h1>
<p>底部内容</p>
</section>
</body>
</html>
2、子页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>子页面</title>
</head>
<body>
<section>
<h1>顶部导航</h1>
<p>顶部内容</p>
<hr>
</section>
{% extends "base.html" %}
{% block content %}
<p>这里是content块的填充内容</p>
{% endblock content %}
{% block abc %}
<ul>内容
{% i for in name %}
<li>{{i}}</li>
{% endfor %}
</ul>
{% endblock abc %}
<section>
<hr>
<h1>底部</h1>
<p>底部内容</p>
</section>
</body>
</html>
3、view与urls
view.py
from django.shortcuts import render
def son(request)
contex={"name":["A","B","C"]}
return render(request,"son.html",context)
urls.py
from django.conf.urls import url
urlpatterns=[
url(r'^son$',view.son)
]