模版继承
理解模版继承:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<title>{% block title %}My amazing site{%/span> endblock %}</title>
</head>
<body>
<div class="ad_con">
{% block sidebar %}
<ul>
<li><a href="/">index</a></li>
<li><a href="/static/">document</a></li>
</ul>
{% endblock %}
</div>
<div class="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
一般我们把这个叫做基础模版base.html,作为其他模版的父模版。
子模版:
{% extends "base.html" %}//先写上从哪里继承的模板
{% block title %}this is index{% endblock %}//用这个数据去替换掉模板里的内容
{% block content %}
{% for entry in blog_entries %}//用的是循环来显示内容
<h2>{{ entry.title }}</h2>
<p>{{ entry.body }}</p>
{% endfor %}这个是标签的结束标志
{% endblock %}