Template Error: Invalid block tag: 'endblock', expected 'empty' or 'endfor'

3,609 views
Skip to first unread message

Homer

unread,
Mar 24, 2012, 8:56:24 PM3/24/12
to django...@googlegroups.com
I tried to create an index webpage but Django told me I had a template error: 

Invalid block tag: 'endblock', expected 'empty' or 'endfor'

Here is the code of index.html:

{% extends "base.html" %}

{% block title %}Home{% endblock %}
{% block content %}

<h2>Welcome to So Easy! 学中文</h3>

<h3>Showcase</h3>
<table>
<tr>
{% for item in item_list|slice:":3" %}
<td>
<a href="{{ item.get_absolute_url }}"><b>{{ item.name }}</b><br />
{% if item.photo_set.count %}
<img src="{{ item.photo_set.all.0.image.thumb_url }}" />
{% else %}
<span>No Photos (yet)</span>
{% endif %}
</a>
</td>
<% endfor %>
</tr>
</table>
<p><a href="{% url item_list %}">View the full list;</a></p>

{% endblock %}    #Error Here
{% block footer %}

I hope someone can help me. Thanks!

Jesramz

unread,
Mar 24, 2012, 9:30:14 PM3/24/12
to Django users
Is there an {% endblock footer %} ?

Sam Lai

unread,
Mar 26, 2012, 6:12:56 AM3/26/12
to django...@googlegroups.com
On 25 March 2012 11:56, Homer <hi...@foxmail.com> wrote:
> I tried to create an index webpage but Django told me I had a template
> error:
>
> Invalid block tag: 'endblock', expected 'empty' or 'endfor'
>
> Here is the code of index.html:
>
> {% extends "base.html" %}
>
> {% block title %}Home{% endblock %}
> {% block content %}
>
> <h2>Welcome to So Easy! 学中文</h3>
>
> <h3>Showcase</h3>
> <table>
> <tr>
> {% for item in item_list|slice:":3" %}
> <td>
> <a href="{{ item.get_absolute_url }}"><b>{{ item.name }}</b><br />
> {% if item.photo_set.count %}
> <img src="{{ item.photo_set.all.0.image.thumb_url }}" />
> {% else %}
> <span>No Photos (yet)</span>
> {% endif %}
> </a>
> </td>
> <% endfor %>

This line should be {% endfor %}.

> </tr>
> </table>
> <p><a href="{% url item_list %}">View the full list;</a></p>
>
> {% endblock %}    #Error Here
> {% block footer %}
>
> I hope someone can help me. Thanks!
>

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Dn_zBeC7tnYJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Sam Lai

unread,
Mar 26, 2012, 6:17:07 AM3/26/12
to django...@googlegroups.com
On 25 March 2012 11:56, Homer <hi...@foxmail.com> wrote:
> I tried to create an index webpage but Django told me I had a template
> error:
>
> Invalid block tag: 'endblock', expected 'empty' or 'endfor'
>
> Here is the code of index.html:
>
> {% extends "base.html" %}
>
> {% block title %}Home{% endblock %}
> {% block content %}
>
> <h2>Welcome to So Easy! 学中文</h3>
>
> <h3>Showcase</h3>
> <table>
> <tr>
> {% for item in item_list|slice:":3" %}
> <td>
> <a href="{{ item.get_absolute_url }}"><b>{{ item.name }}</b><br />
> {% if item.photo_set.count %}
> <img src="{{ item.photo_set.all.0.image.thumb_url }}" />
> {% else %}
> <span>No Photos (yet)</span>
> {% endif %}
> </a>
> </td>
> <% endfor %>

This line should be {% endfor %}.

> </tr>


> </table>
> <p><a href="{% url item_list %}">View the full list;</a></p>
>
> {% endblock %}    #Error Here
> {% block footer %}
>
> I hope someone can help me. Thanks!
>

Reply all
Reply to author
Forward
0 new messages