如何在django模板中迭代字典的列表值

时间:2018-02-21 07:32:23

标签: python django dictionary django-templates

我有一个字典,其中值在列表中

{
    'Fees': ['88000', '88000'],
    'ROll Number': ['I0', 'I1'],
    'Mark': [10, 10]
}

所以我试图在表格中插入这些数据,所以我的Django模板是

  <table>
      <thead>
        <tr>
        {% for k, v in loan_bank_info.items %}
            <th>{{ k }}</th>
        {% endfor %}
        </tr>
      </thead>
      <tbody>
      <tr>
      {% for k, value in loan_bank_info.items %}
        {% for v in value %}  
          <td>{{ v }}</td>
          {% endfor %}
      {% endfor %}
      </tr>
    </tbody>
  </table>

但是在表值中打印如下,

  Fees          ROll Number     Mark
  88000 88000    I0 I1           10 10

但我想要的是 -

Fees            ROll Number     Mark
  88000          I0             10 
  88000          I1             10

如何在Django模板中迭代列表值

1 个答案:

答案 0 :(得分:1)

您可以遍历列表。像下面的东西

<tr>
      {% for k, value in loan_bank_info.items %}
        {% for v in value %}
            {% for i in v %} 
              <td>{{ i }}</td>
            {% endfor %}
          {% endfor %}
      {% endfor %}
      </tr>
相关问题