2017-07-17 734 views
0

我遇到了一个关于在django模板中填充我的html数组的小问题。使用django/python填充html数组的正确方法

我想打印一个表格到一行。相反,一排各种形式的(这就是我与示例代码得到的只是在那里):

<thead> <!-- cétait td à la place de th --> 
      <tr> 
      {% for entry in headers %} 
      <th> 
      {{ entry }} 
      </th> 
      {% endfor %} 
      </tr>    

      </thead> 
      <tbody> 

       <tr> 
       {%for entry in entries%} 
       {%for cle, valeur in entry.all_form_entry_json%} 
       {%for key, valor in headersLoop%} 
       {%if key == cle%} 

       <td> {{valeur}}</td> 


       {% endif %} 

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

      </tbody> 

结果如如下:

enter image description here

你可以看到,所有的数据打印到右上角并超出数组限制。

我如何得到这样的结果?

enter image description here

这是可能只与HTML办呢?或者我应该创建一个js或css文件并将其导入到此template.html?

谢谢你的回答!

回答

3

我认为你错了地方的HTML标签<tr>, 标签<tr>应该内{% for环..

<thead> 
    <tr> 
    {% for entry in headers %} 
    <th>{{ entry }}</th> 
    {% endfor %} 
    </tr> 
</thead> 

<tbody> 
{% for entry in entries %} 
    <tr> 
    {% for cle, valeur in entry.all_form_entry_json %} 
     {% for key, valor in headersLoop %} 
     {% if key == cle %} 
      <td>{{ valeur }}</td> 
     {% endif %} 
     {% endfor %} 
    {% endfor %} 
    </tr> 
{% endfor %} 
</tbody> 
+0

谢谢。这工作正常! – Karro