I have a template which has two template variables list_of_books, search_results
First i am checking whether results exists for any one of the variables , if not exists it should display Books not available as below
Next if search_results variable has results, we should loop and print the data,
else if list_of_books variable has results , we should loop and print the data
{% if list_of_books or search_results %}
<table border="0" align="left" width="70%">
{% if search_results %}
{% for book in search_results %}
{% else %}
{% for book in list_of_books %}
{% endif %}
<tr>
<td>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No Books available.</p>
{% endif %}
But by the above html code i am getting the below error, actually where i am making mistake in writing template tags ?
Error during template rendering
In template /home/virtualenvironment/apps/books/templates/books/list_of_books.html, error at line 23
Invalid block tag: 'else', expected 'empty' or 'endfor'
20 <table border="0" align="left" width="70%">
21 {% if search_results %}
22 {% for book in search_results %}
23 {% else %}
24 {% for book in list_of_books %}
25 {% endif %}
26 <tr>
27 <td>
28 <a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
29 </td>
30 </tr>
31 {% endfor %}
32 </table>