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
时间: 2024-12-16 10:48:44