jinja2 到 post 网络上的数据框表
jinja2 to post dataframe tables on web
我正在使用 Flask、Jinja2 模板(html 文件)来 post 熊猫数据框表,这些表存储在 ABC.py 的结果中。
Table 看起来像:Image
我正在使用字典打印它,但它的格式不正确
<div class="col-sm-5 col-sm-offset-1">
{% if results is not none %}
<h2>Compare</h2>
<br>
<div id="results">
<table class="table table-striped" style="max-width: 300px;">
<thead>
<tr>
<th>Specifications</th>
<th>part1</th>
<th>part2</th>
</tr>
</thead>
{% for key,value in results.iterrows() %}
<tr> <option value = {{value[0]}} </option> </tr>
<tr>
<option value = "{{value[0]}}">{{value[1]}}</option>
</tr>
# <option value="{{ value['0']}}">{{value['1'] }}</option>
{% endfor %}
</table>
</div>
{% endif %}
</div>
必须使用 jinja2 模板做其他事情,但停留在非常底层。
有什么建议吗
谢谢
您可以通过将以下内容添加到模板文件来直接呈现 table:
{{ results.to_html() | safe}}
我正在使用 Flask、Jinja2 模板(html 文件)来 post 熊猫数据框表,这些表存储在 ABC.py 的结果中。 Table 看起来像:Image
我正在使用字典打印它,但它的格式不正确
<div class="col-sm-5 col-sm-offset-1">
{% if results is not none %}
<h2>Compare</h2>
<br>
<div id="results">
<table class="table table-striped" style="max-width: 300px;">
<thead>
<tr>
<th>Specifications</th>
<th>part1</th>
<th>part2</th>
</tr>
</thead>
{% for key,value in results.iterrows() %}
<tr> <option value = {{value[0]}} </option> </tr>
<tr>
<option value = "{{value[0]}}">{{value[1]}}</option>
</tr>
# <option value="{{ value['0']}}">{{value['1'] }}</option>
{% endfor %}
</table>
</div>
{% endif %}
</div>
必须使用 jinja2 模板做其他事情,但停留在非常底层。 有什么建议吗
谢谢
您可以通过将以下内容添加到模板文件来直接呈现 table:
{{ results.to_html() | safe}}