2017-02-11 54 views
0

我试图产生闪光灯的使用环路表格标题,但我每次使用后得到新的线路印刷新线防止烧瓶:从一个循环

{% extends "layout.html" %} 

{% block title %} 
    Portfolio overview 
{% endblock %} 

{% block main %} 

{% for variable in variables -%} 
    {% for key, value in variable.items() -%} 
    <table> 
     <thead><th>{{ key }}</th></thead> 
    {% endfor -%} 
    {% for key, value in variable.items() -%}  
    <tbody>  
    <td>{{ value }}</td> 
    </tbody>    
    {% endfor -%} 
{%- endfor -%} 
    </table> 
<h2>Cash available (US$): {{ cash }}</h2> 
<h2>Total portfolio value (US$): {{ wealth }}</h2>  

{% endblock %} 

Result

不过,我想获得这 Desired result

回答

0

给这个镜头;

{% extends "layout.html" %} 

{% block title %} 
    Portfolio overview 
{% endblock %} 

{% block main %} 

<table> 
    {% for variable in variables %} 
     <thead> 
      {% for key, value in variable.items() %} 
       <th>{{ key }}</th> 
      {% endfor %} 
     </thead> 
     <tbody> 
      {% for key, value in variable.items() %}  
       <td>{{ value }}</td> 
      {% endfor %} 
     </tbody>    
    {% endfor %} 
</table> 
<h2>Cash available (US$): {{ cash }}</h2> 
<h2>Total portfolio value (US$): {{ wealth }}</h2>  

{% endblock %} 

我刚刚修复了for循环的位置。

+0

非常感谢这 - 我现在看到我的错误! – idol2k