子模板也可以在 django 中使用子模板吗?



我的子模板路径 project/sales/templates/sales/table.html。

它扩展了另一个子模板sale_summary_change_list.html。

{% extends 'sales/sale_summary_change_list.html' %}
{% block result_list %}
<div class="results">
<table>
<thead>
<tr>
{% for header in table %}
<th>
<div class="text">
<a href="#">{{ header }}</a>
</div>
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in summary %}
<tr class="{% cycle 'row1' 'row2'}">
<td> {{ row.color_pref }} </td>
<td> {{ row.total | intcomma }} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

父模板也位于同一文件夹中。(project/sales/templates/sales/sale_summary_change_list.html(

{% extends 'admin/change_list.html' %}
{% load humanize %}
{% block content_title %}
<h1> Sales Summary </h1>
{% endblock %}
{% block result_list %}
{% block table %} {% endblock %}
{% endblock %}
{% block pagination %}{% endblock %}

但是,我的子模板没有出现。我做错了什么?

你做事的方式不对。只需{% extends 'sale_summary_change_list.html' %}此代码块替换为此代码{% extends 'sales/sale_summary_change_list.html' %}即可。它可能对你有用。

相关内容

最新更新