切换主题
五、模板继承
一、基础使用
1、定义父模板base.html
python
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="base.css" />
<title>{% block title %}{% endblock %}</title>
{% block head %}{% endblock %}
</head>
<body>
<div id="body">{% block body %}{% endblock %}</div>
<div id="footer">
{% block footer %}
©Copyright 2008 by <a href-"http://domain.invalid/">you</a>
{% endblock %}
</div>
</body>
</html>
2、定义子模板children.html
python
{% extends "base.html" %}
{% block title %}首页{% endblock %}
{% block head %}
<style type="text/css">
.detail{
color:red;
}
</style>
{% endblock %}
{% block content %}
<h1>这里是首页</h1>
<p class="detail">
首页的内容
</p>
<% endblock %>
二、引入模板
python
{% include "_contact.html" %}