Django: Invalid block tag on line 14: 'else'. Did you forget to register or load this tag?

Issue

During Django tutorial I’ve got an issue with index.html file.
I can’t handle this exception:

Invalid block tag on line 14: ‘else’. Did you forget to register or load this tag?

My index.html is like this:

    {% if latest_questions %)
    <ul>
        {% for question in latest_questions %}
             <li> <a href="/polls/{{question.id}}"><b>{{question.question_text}}</b></a></li>
        {% endfor %}
    </ul>
{% else %}
    Something else.
{% endif %}

I really don’t understand why it don’t recognize “else”.

Solution

The problem is with your if tag.

Replace:

 % if latest_questions %)

with:

 {% if latest_questions %}

Answered By – Julien Salinas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published