'How do I set a class in a <tr> tag based on a value in a <td> tag using jinja2?

I'm iterating over a list of dictionaries that creates a table in jinja. However, I want to apply formatting on a class in a <tr> tag I assigned based on a value in the proceeding <td> tags.

Essentially I'm trying to achieve the following: If the value 'nRed' is in a <td> tag set <tr class='nred'>. Later I will use CSS to format that row based on the class. I'm not sure how to accomplish this without creating new <tr> tags for every <td> tag.

Here is my body:

<body>
    <table>
        <thead>
            <tr>
                {% for column in columns %}  
                    <th>{{ column }}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            {% for row in rows %}
                {% for key, value in row.items() %}
                    {% if value == "nRed" %}
                        <tr class="nred"> 
                            <td>{{ value }}</td>
                        </tr>>
                    {% else %}
                        <tr> 
                            <td>{{ value }}</td>
                        </tr>
                    {% endif %}
                {% endfor %}
            {% endfor %}
        </tbody>
    </table>
</body>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source