Home > Software design >  How to color value in list with django?
How to color value in list with django?

Time:01-12

I am using the django framework. And I have a list with values. And the values from that list are displayed on a template. And I want to color one value red from the list.

So this is the list:

 self.list_school_values = [
            "12bg00",
            "Basisschool Vroonestein",
            "Lohengrinhof 1517, 3438RA NIEUWEGEIN Utrecht",
            "Lohengrinhof 1517, 3438RA NIEUWEGEIN Utrecht",
            "mevr. W.M. van den Brink",
            "030-6037291",
            "[email protected]",
            "196",
            "Verdi import B.V.",
            "dhr. Kees Kooijman",
            "Koopliedenweg 38 , 2991 LN BARENDRECHT",
            "[email protected]",
        ]

and the labels_list:

 self.list_school_labels = [
            "Brinnummer",
            "School",
            "Bezoekadres",
            "Postadres",
            "Contactpersoon",
            "Telefoonnummer",
            "Emailadres",
            "Aantal leerlingen",
            "Leverancier",
            "Contactpersoon",
            "Adres",
            "Email leverancier",
        ]

and the template looks:

<div >
                                <div >
                                    <div >
                                        <table>
                                            <tr>
                                                <th>Gegevens school </th>
                                                <th>waardes school contract</th>
                                            </tr>
                                            {% for value0, value1 in content %}
                                            <tr>
                                                <td>
                                                    {{value0}}
                                                </td>
<td >
                                                    {{value1}}
                                                </td>



                                            </tr>
                                            {% endfor %}
                                        </table>
                                    </div>
                                </div>
                            </div>

and css:

.red {
    color: red;
}

and this is part of views.py:

def post(self, *args, **kwargs):
        content = ""       

But the value is not colored red.

Question: how to color the value from the list red?

CodePudding user response:

You can try this :

<div >
<div >
    <div >
        <table>
            <tr>
                <th>Gegevens school </th>
                <th>waardes school contract</th>
            </tr>
            {% for value in list_school_values %}
                <tr>
                    <td>{{value}}</td>
                    <td >{{value}}</td>
                </tr>
            {% endfor %}
        </table>
    </div>
</div>
  • Related