U
U
Uno di Palermo2019-08-15 13:58:30
Django
Uno di Palermo, 2019-08-15 13:58:30

How in Django 2.2 to make the "if" condition inside the "for" work?

hello, this is it:

<tbody>
    {% for i in all %}
       <tr>
            <td class="grey"> {{ i.0 }} </td>
            <td class="grey">{{ i.1 }}</td>
            <td class="thick">{{ i.2 }}</td>
            <td>{{ i.3 }}</td>
            <b><td style="color: {% if i.4|floatformat > 0 %} green {% else %} red {% endif %} ;"> {{ i.4 }} </td> - не работает              
            <td style="color:{% if i.4|floatformat > 0 %} green {% else %} red {% endif %};"> {{ i.5 }} </td> </b> - не работает
        </tr>
    {% endfor %}
</tbody>

an example of i.4 value is "-0.34" or "+0.34"
i.e. if in i.4 there is + it should be green, and "-" - red,
now everything i.4 is red,
how to be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alternativshik, 2019-08-15
@rogerCopy

so maybe there is a string, not a number, so "doesn't work"?

R
Roman Kitaev, 2019-08-15
@deliro

Throw out the filter |floatformat. It gives a string representation of a number

A
Alexey Guest007, 2019-08-15
@Guest007

greater than 0 means there can be values ​​​​and less? If only 0 or more, then you can generally write {% if i.4 %}.
If there can be negative ones, then make sure that there will be no lines and {% if i.4 > 0 %}
Something like this...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question