Jinja在for循环中查找键

时间:2017-12-12 04:43:21

标签: python django jinja2

我将来自view.py的2组数据传递给我的html文件。 但网页中只显示一组数据。

HTML:

<h3>Database: A</h3>
           <table>
              <tr>
                  <th>A</th>
                  <th>Counts A-1</th>
                  <th>Counts A-2</th>
                  <th>Value</th>
              </tr>
              {% load lookup %}
              {% for i in Amatch %}
             <tr>
                 <th> {{ Amatch|lookup:forloop.counter0 }} </th>
                 <td> {{ Amatchtotal|lookup:forloop.counter0 }} </td>
                 <td> {{ AmatchCount|lookup:forloop.counter0 }} </td>
                 <td> {{ Avalue|lookup:forloop.counter0 }} </td>
             </tr>
             {% endfor %}
          </table>

    <h3>Database: B</h3>
          <table>
             <tr>
                 <th>B</th>
                 <th>Counts B-1</th>
                 <th>Counts B-2</th>
                 <th>Value</th>
             </tr>
            {% load lookup %}
            {% for i in Bmatch %}
            <tr>
                <th> {{ Bmatch|lookup:forloop.counter0 }} </th>
                <td> {{ Bmatchtotal|lookup:forloop.counter0 }} </td>
                <td> {{ BmatchCount|lookup:forloop.counter0 }} </td>
                <td> {{ Bvalue|lookup:forloop.counter0 }} </td>
            </tr>
            {% endfor %}
         </table>

view.py

return render(request, 'analysis/result.html', {'Amatch':Amatch, 'Amatchtotal':Amatchtotal, 'AmatchCount':AmatchCount, 'A_re':A_re, 'Avalue':Avalue, 'Bmatch':Bmatch, 'Bmatchtotal':Bmatchtotal, 'BmatchCount':BmatchCount, 'B_re':B_re, 'Bvalue':Bvalue,})

应该按照我的预期在页面上显示两组数据。 但是,只有来自B组的数据显示在页面上。 我试图切换A组和B组的顺序,但仍然只显示B组。

我非常确定通过在终端中检查数据来成功传递数据。

我的代码有什么问题吗?

0 个答案:

没有答案