【问题标题】:Python list value show in html tablePython列表值显示在html表中
【发布时间】:2021-09-30 13:11:12
【问题描述】:

下面显示我的python返回:

 return render(request,'school\Views\Spredictions.html'{'len':length,'final':Ol_result,'data':marks_sheet})

这里,final : - ['pass','pass',''fail,'fail'] 像这样

下面显示我的html代码

                         <tbody>

                            {%for m in data%}
                                    <tr>
                                        <td>{{m.student_name}}</td>

                                        <td>{{final}}</td>

                                      </tr>
                                  {%endfor%}

                                </tbody>

我想在表格界面中一个一个显示值,但是显示是这样的

output of table

如何解决这个问题。任何人都可以帮助我 谢谢

【问题讨论】:

  • 我认为你必须为每个 lopp 做第二个预测结果
  • @Elikill58 我试试这个,但如何同时添加那个 for 循环。因为学生姓名有“for-loop”
  • 你可以使用嵌套的for循环,一个for循环在另一个for循环中
  • Yeoh,但是那种情况下,学生姓名会根据预测结果大小重复@Rasheedkotoor
  • 我认为你正试图在 Django 中循环两个列表 together,这是你想要的吗?见Iterating through two lists in Django templates

标签: python html django


【解决方案1】:

我使用 zip() 创建了一个列表

mylist1 = zip(student_name1,Ol_result)
return render(request,'school\Views\Spredictions.html',{'mylist':mylist1,'final':Ol_result,'data':marks_sheet})

HTML代码

  <tbody>
        {%for item1, item2 in mylist%}
            <tr>
                <td>{{item1}}</td>
                 <td>{{item2}}</td>

              </tr>
           {%endfor%}
</tbody>

问题解决了

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    相关资源
    最近更新 更多