0

Estou com dificuldades aqui para exibir no template o retorno de um campo booleano. Preciso exibir o nome do campo se ele for verdadeiro no template.

models

topo = models.BooleanField()

views

def view_ieis(request, pk):
    ieis = IEIS.objects.get(pk=pk)
    return render(request, 'ieis/view.html', {'ieis': ieis,})

template.html

<div table class="table table-reponsive">
    <table class="table table-bordered">
      <thead>
        <tr>

          <th scope="col">Tipo</th>

        </tr>
      </thead>
      <tbody>
        <tr>
                <td>
                    {% if topo is True %}
                        <p>Topo</p>
                    {% endif %}

           </td>
        </tr>
      </tbody>
    </table>
</div>

1 Resposta 1

0

Tente

{% if ieis.topo is True %}
   <p>Topo</p>
{% endif %}

Ou

{% if ieis.topo == True %}
   <p>Topo</p>
{% endif %}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .