[Answered ]-How to add a style in django

1👍

There are two mistakes here:

  1. a template tag, like {% if … %} [Django-doc] is wrapped in curly brackets with percentages ({% … %}), you are missing the percentages (%); and
  2. a string literal is wrapped between quotes, so 'red', instead of red.

You thus implement this with:

<td {% if car.color == 'red' %}style="background-color: red;"{% endif %}>{{car.color}}</td>

Leave a comment