Jinja查找for循环中的键

2024-06-16 10:53:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我从我的计算机上传递了两组数据视图.py到我的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>

你知道吗视图.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组。你知道吗

我敢肯定,通过在终端中检查数据,可以成功地传递数据。你知道吗

我的代码有什么问题吗?你知道吗


Tags: 数据rehtmltablelookuptrh3td