1.新建base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}父模板文件{% endblock title %}</title>
</head>
<body>
<h1>導航條</h1>
<h1>版權信息</h1>
{% block b1 %}
<h1>這是父模板b1裏面的內容</h1>
{% endblock b1 %}
</body>
</html>
2.新建child.html
{% extends 'booktest/base.html' %}
{% block title %}子模板文件{% endblock title %}
{% block b1 %}
{{block.super}}
<h1>這是子模板b1裏面的內容</h1>
{% endblock b1 %}
3.定義視圖函數
def temp_inherit(request):
return render(request,'booktest/child.html')
4.url
url(r'^temp_inherit$', views.temp_inherit),
5.測試