简体   繁体   中英

How to iterate over a list value of a dictionary in django template

I have a dictionary where value are in list

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

So I am trying to insert this data in table, SO my Django template are

  <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>

but in table value are printing as follow,

  Fees          ROll Number     Mark
  88000 88000    I0 I1           10 10

But what I want is -

Fees            ROll Number     Mark
  88000          I0             10 
  88000          I1             10

how to iterate over list value in Django template

You can just iterate over the list. Something like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM