我正在尝试使用flash中的循环生成表格标题但是我在每个之后都获得了新的行:
{% 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 %}
但是,我想得到这个 Desired result
答案 0 :(得分: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循环的位置。