【发布时间】:2013-08-16 07:40:26
【问题描述】:
我开始使用 Django,我正在尝试制作一个模块化模板,但我不知道如何。现在,我有以下文件:
1- base.html(提供所有网站的基本布局):
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>My site</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/bootsrap.min.css' %}" />
</head>
<body>
<h1>Test title</h1>
{% block content %}
{% endblock %}
</body>
</html>
2- index.html(主数据库读取)
{% extends 'base.html' %}
{% block content %}
{% if latest_smartphones_list %}
<ul>
{% for s in latest_smartphones_list %}
<li><a href="#">{{ s.brand }} {{ s.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No smarphones available.</p>
{% endif %}
{% endblock %}
最后,我想添加第三个文件,名为 menu.html,其中包含站点菜单。我想将它添加到 base.html 文件中。我一直在考虑通过以下方式来做,但我不工作:
{% load 'menu.html' %}
非常感谢您的帮助!
【问题讨论】:
-
三级模板是template inheritance reference documentation中的一个例子
标签: python html django templates