[Answer]-Invalid block tag: 'else', expected 'empty' or 'endfor' in django template

1👍

The best way to solve this is probably to make sure that views which use the template just use the same variable name.

If that’s not possible I’d do this instead:

{% if list_of_books or search_results %}
    <table border="0" align="left" width="70%"> 
    {% if search_results %}
        {% include "book_listing.html" with books=search_results %}
    {% else %}    
        {% include "book_listing.html" with books=list_of_books %}
    {% endif %}
    </table>
{% else %}
    <p>No Books available.</p>
{% endif %}

And then put this in book_listing.html:

{% for book in books %}
  <tr>
    <td>  
      <a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
    </td>
  </tr>
{% endfor %}

0👍

<span>
    {%if booking.DiscountedFare == booking.TotalFare %}
        Rs.{{ booking.TotalFare }}

    {% else %}   
        Rs.{{ booking.DiscountedFare }}         

    {% endif %}
</span>

Leave a comment