我正在尝试创建 base.html 并在基础上加载几个名为“nav.html”、“contents.html”和“footer.html”的子模板。每当我访问 /base.html 时,我想让所有三个子模板都加载到 base.html 页面上。
基本.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<nav class="navbar">
<div class="nav">
{% block nav %}{% endblock %}
</div>
</nav>
<div class="content">
{% block contents %}{% endblock %}
</div>
<div class="footer">
{% block footer %}{% endblock %}
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
导航.html:
{% extends "base.html" %}
{% block title %}Page Title{% endblock %}
{% block nav %}
<p>Here goes the nav</p>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
内容.html:
{% …Run Code Online (Sandbox Code Playgroud) django extends multiple-inheritance django-templates template-inheritance