Color coding cells in a table based on the cell value using Jinja templates Color coding cells in a table based on the cell value using Jinja templates flask flask

Color coding cells in a table based on the cell value using Jinja templates


The easiest way would be to put this display logic in your template:

<table>    {% for row in data %}    <tr>        {% for item in row %}            {% if item <= 10 %}                <td class="under-limit">{{ item }}</td>            {% else %}                <td>{{ item }}</td>            {% endif %}        {% endfor %}    </tr>    {% endfor %}</table>

Then, in your CSS you can use:

.under-limit { background-color: red; }


<table>   {% for row in row %}       {% if item <= 10 %}       <tr style ="background-color: red">           <td> {{ item }} </td>       </tr>       {% else %}       <tr>           <td> {{ item }} </td>       </tr>       {% endif %}    {% endfor %}</table>

This works for me.