2017-07-17 736 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