2
votes

I'm going through the tango with django tutorial and everything was going well until this problem came up in one of my templates.

It says that it was expecting and endif tag but it found an else tag instead which I don't understand because the inner if/else/endif clause doesn't cause any problems.

I have seen some people having similar issues with custom tags that they did not import at the beginning of their script but these are not custom tags so I don't know what the issue might be. Maybe a syntax error I'm missing?

<body>
    {% if category_name %}
        <h1>{{ category_name }}</h1>
        {% if pages %}
            <ul>
                {% for page in pages %}
                    <li><a href="{{ page.url }}">{{ page.title }}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <strong>No pages currently in category.</strong>
        {% endif % }
    {% else %}                <= error here: "expected endif instead of else"
        The specified category {{ category_name }} does not exist!
    {% endif %}
</body>

I am using vim with shiftwidth=3, tabstop=3, expandtab. I don't know if that may have to do with this but just in case.

1
Would it be possible to post the full traceback? - David Robinson
Thank you very much for your help David, but as Tony pointed out I have a typo in the inner endif (there's a space between the '%' and the '}') which I didn't see because of tunnel vision. My bad. Sorry for posting something like this and thanks again for the help. - Abraham Escalante

1 Answers

9
votes

You have a little typo: One of your statements ends with {% endif % } instead of {% endif %} (remove a space).