jinja2将数据表发布到Web上

Mus*_*aan 0 jinja2 flask pandas webapp2

我正在使用Flask,Jinja2模板(html文件)发布存储在ABC.py结果中的熊猫数据框表。表格看起来像:图片

我正在使用字典进行打印,但是格式不正确

<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>
Run Code Online (Sandbox Code Playgroud)

必须使用jinja2模板来做其他事情,但要停留在最底层。有任何建议请。

谢谢

All*_*len 5

您可以通过将以下内容添加到模板文件中来直接呈现表格:

{{ results.to_html() | safe}}
Run Code Online (Sandbox Code Playgroud)