base.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<h1>My helpful timestamp site</h1>
{% block content %}{% endblock %}
{% block footer %}
<hr>
<p>Thanks for visiting my site.</p>
{% endblock %}
</body>
</html>
{% extends "base.html" %}
{% block title %}The current time{% endblock %}
{% block content %}
<p>It is now {{ current_date }}.</p>
{% endblock %}
很不理解 这个东西 怎么就继承了呢? base.html <title>{% block title %}{% endblock %}</title> 这么写是什么意思啊?
大家讲道理2017-04-18 09:18:22
You can understand it this way
base.html is the master template
a.html is the child template
{% block title %}{% endblock %} You can understand it as a placeholder or variable
As long as your a.html page inherits bash.html with {% extends "base.html" %}
In a.html It contains all the content in base.html, and you can use {% block title %}abc{% endblock %} to modify the value of your subpage
黄舟2017-04-18 09:18:22
You can study the source code implementation process. As for <title>{% block title %}{% endblock %}</title> here is a simple Update mechanism