3

I am using Flask ,Jinja2 template(html file) to post the panda dataframe tables which are stored in results in ABC.py. Table looks like :Image

I am using dictionary to print it but it is not coming in right format

<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>

Have to do other things using jinja2 templates but stuck at very ground level. Any suggestions please.

Thanks

davidism
  • 121,510
  • 29
  • 395
  • 339
Naomi
  • 57
  • 1
  • 6

1 Answers1

26

You can directly render a table by adding the below to your template file:

{{ results.to_html() | safe}}
Allen Qin
  • 19,507
  • 8
  • 51
  • 67