Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jinja2 to post dataframe tables on web [duplicate]

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

like image 916
Naomi Avatar asked Nov 14 '25 13:11

Naomi


1 Answers

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

{{ results.to_html() | safe}}
like image 171
Allen Avatar answered Nov 17 '25 10:11

Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!