<!DOCTYPE html>
<html>
<head>
{% block head %}
{% endblock %}
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
<title>Example</title>
<h1>Example Django</h1>
使用django,您可以渲染模板&#34; base.html&#34;但更换块&#34;头&#34;和&#34; body&#34;分别通过模板&#34; head.html&#34;和&#34; body.html&#34;?
答案 0 :(得分:3)
如果我理解你,你需要include
标签
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include
<!DOCTYPE html>
<html>
<head>
{% include "head.html" %}
</head>
<body>
{% include "body.html" %}
</body>
</html>
答案 1 :(得分:1)
{%include&#34; base.html&#34; %}
{% block head %}
{% include "head.html" %}
{% endblock %}
{% block body %}
{% include "body.html" %}
{% endblock %}