如何将模板插入另一个模板? [英] How do you insert a template into another template?
问题描述
我有一个非常基本的模板(basic_template.html),并且要填写使用另一部分模板格式化的数据。 basic_template.html可能包含使用部分模板格式化的几种东西。
I have a very basic template (basic_template.html), and want to fill in the with data formatted using another partial template. The basic_template.html might contain several things formatted using the partial template.
如何在views.py中构造代码?
How should I structure the code in views.py?
我这样做的原因是,稍后将使用Ajax填充。我是这样做的吗?
The reason I am doing this is that later on the will be filled using Ajax. Am I doing this right?
推荐答案
你可以做:
<div class="basic">
{% include "main/includes/subtemplate.html" %}
</div>
其中 subtemplate.html
是另一个Django模板。在这个 subtemplate.html
中,您可以将使用Ajax获取的HTML。
where subtemplate.html
is another Django template. In this subtemplate.html
you can put the HTML that would be obtained with Ajax.
您还可以包括模板多次:
You can also include the template multiple times:
<div class="basic">
{% for item in items %}
{% include "main/includes/subtemplate.html" %}
{% endfor %}
</div>
这篇关于如何将模板插入另一个模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!