Bimons
Bimons

Reputation: 241

generating tables with jinja2

I am using the below code to make a table:

<table style="height: 100%;">
<tbody>
  {% for row in row_data %}
  {% for col, row_ in zip(column_names, row) %}
<tr>     
  {% if col == images_column %}
    <td><img src="{{ row_ }}" alt="Example" width="200"> </td>
 {% endif %}

  {% endfor %}
      {% endfor %}

</tr>
</tbody>
</table>

But I need it to be one row with infinite columns, instead of one column with infinite rows, as it is currently

I have been moving around code for hours and cant seem to figure it out. Any clues?

Upvotes: 0

Views: 548

Answers (1)

Croc
Croc

Reputation: 838

Without knowing the data types of your variables, I assume something like this should work:

<table style="height: 100%;">

{% for row in row_data %}
  <tr>
    {% for col in column_names) %}
      {% if col == images_column %}
         <td><img src="{{ row[col] }}" alt="Example" width="200"> </td>
      {% endif %}
    {% endfor %}
  </tr>
{% endfor %} 

</table>

Upvotes: 1

Related Questions