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

后端 未结 2 1635
梦如初夏
梦如初夏 2020-12-19 12:39

I have a simple flask app and need to display a table of values, with the cell backgrounds colour coded based on the cell value according to thresholds. I\'m generating the

2条回答
  •  悲哀的现实
    2020-12-19 13:20

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

    
        {% for row in data %}
        
            {% for item in row %}
                {% if item <= 10 %}
                    
                {% else %}
                    
                {% endif %}
            {% endfor %}
        
        {% endfor %}
    
    {{ item }}{{ item }}

    Then, in your CSS you can use:

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

提交回复
热议问题