python - django模板继承问题求助
大家讲道理
大家讲道理 2017-04-18 09:16:22
0
2
229
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> 这么写是什么意思啊?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
大家讲道理

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

黄舟

You can study the source code implementation process. As for <title>{% block title %}{% endblock %}</title> here is a simple Update mechanism

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template