在Django中具有嵌套表的问题渲染

问题描述 投票:0回答:1

我正在尝试互相循环两个表。我有一个任务列表,每个任务都有一个材料列表。我想彼此相邻的桌子。但是,下面的代码不会将第二个任务呈现为列。因此,当循环时,似乎表结构已被破坏。我正在使用Django / Python。

<div class="table-responsive">
    <table id="taskTable" class="table">
        {% for task in projecttype.projecttask_set.all %}
            <h5>Task - {{ task.name }}</h5>
            <thead class="alert-success">
            <tr>
                <th>Quantity</th>
                <th>Units</th>
                <th>Cost</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>{{ total_units_required }}</td>
                <td>{{ task.base_unit_label }}</td>
                <td>{{ task.base_unit_cost }}</td>
            </tr>
            </tbody>
            <table id="materialTable" class="table">
            <thead>
            <tr class="alert-info">
                <th>Material</th>
                <th>Cost per Task Unit</th>
                <th>Material Cost</th>
                <th>Total Cost</th>
            </tr>
            </thead>
            {% for material in task.materials.all %}
                <tbody>
                <tr>
                    <td>{{ material.name }}</td>
                    <td>{{ material_quantity_per_task_base_unit }}</td>
                    <td>{{ total_material_quantity }}</td>
                    <td>{{ total_material_cost }}</td>
                </tr>
                </tbody>
            {% endfor %}
            </table>
        {% endfor %}
    </table>
</div>

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9QNnk5Mi5wbmcifQ==” alt =“在此处输入图像描述”>

python html django html-table datatables
1个回答
0
投票

我遇到了同样的问题。嵌套表必须在表单元格内]

例如

<table>
    <tr>
    <td>
        <table>
        ...
        </table>
    </td>
    </tr>
</table>



© www.soinside.com 2019 - 2024. All rights reserved.