Display a boolean field result if it is True

Asked

Viewed 36 times

0

I’m having difficulty here to display the return of a Boolean field in the template. I need to display the field name if it is true in the 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,})

html template.

<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 answer

0

Try

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

Or

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.