您的位置:首页 > 其它

Template 模板的继承

2014-08-04 21:47 120 查看
index.html

{% extends "base.html" %}
{% block content %}
<h1>Hi, {{user.nickname}}!</h1>
{% for post in posts %}
<div><p>{{post.author.nickname}} says: <b>{{post.body}}</b></p></div>
{% endfor %}
{% endblock %}


base.html

<html>
<head>
{% if title %}
<title>{{title}} - microblog</title>
{% else %}
<title>microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>


关键语句:{% block content %} wz {% endblock %} ; {% extends 'base.html' %} {% block content %} xxxxxx{% endblock %}

index.html 继承 base.html 简单理解,将xxxxxx插入wz位置,但最终渲染的模板是 base.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: