is there a way to loop over two lists simultaneously in django?

前端 未结 6 1222
小鲜肉
小鲜肉 2020-12-01 16:08

I have two list objects of the same length with complementary data i want to render is there a way to render both at the same time ie.

{% for i,j in table,          


        
6条回答
  •  半阙折子戏
    2020-12-01 16:51

    Use python's zip function and zip the 2 lists together.

    In your view:

    zip(table, list)
    

    In your template, you can iterate this like a simple list, and use the .0 and .1 properties to access the data from table and list, respectively.

提交回复
热议问题