django - 如何在django模板的html表中显示多个对象数据
问题描述
我从视图向模板传递了两个查询集对象,它们都具有产品数据及其功能,现在主要问题是如何在 HTML 表中同时显示这两个对象数据?
表结构:
features1 | product1 features value 1 | product2 feature value 1
features2 | product1 features value 2 | product2 feature value 2
...
<tbody>
{% for a in product_data %}{% for b in product_data_2 %}
<tr class="row" style="line-height: 3">
{% if forloop.counter == forloop.parentloop.counter %}
{% for feature_data in a.product_features.all %}{% for feature_data_1 in b.product_features.all %}
<td class="col-lg-4 col-md-4 col-sm-4 col-4" style="text-align: left; font-weight: bold;">
{{ feature_data.feature.feature_name }}
</td>
<td class="col-lg-4 col-md-4 col-sm-4 col-4" style="text-align: center;">
{{ feature_data.product_feature_value }}
</td>
<td class="col-lg-4 col-md-4 col-sm-4 col-4" style="text-align: center;">
{{ feature_data_1.product_feature_value }}
</td>
{% endfor %}{% endfor %}
{% elif forloop.counter < forloop.parentloop.counter %}
something
{% elif forloop.parentloop.counter < forloop.counter %}
something
{% endif %}
</tr>
{% endfor %}{% endfor %}
</tbody>
请尝试回答我试过但没有任何效果
解决方案
推荐阅读
- java - 如何修复连接被拒绝:android studio中的连接错误?
- css - 如何使用 ::theme 伪元素?
- android - 注入改造android kotlin
- ruby - 用于映射部分搜索属性的 Ruby 和 Elasticsearch
- vba - 将字符串连接到具有交替字体格式的范围内
- c# - Test.MainForm.Dispose(bool):没有合适的方法来覆盖 (CS0115)
- python - 将字符串/字符数组加入带有分隔符的单个字符串 [不使用理解、映射等]
- javascript - 在 Vue.js 应用程序中使用来自另一个组件中的一个组件的代码(函数/模板),没有直接关系
- java - java.net.MalformedURLException:未知协议:地图
- python - 无法通过 tor ConnectionRefusedError 发出 python 请求:[WinError 10061]