Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#128 closed defect (worksforme)

IndexError when using invalid {% extends %} in template should be replaced with better error message.

Reported by: espen@… Owned by: adrian
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


First of all the error

There's been an error:

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 190, in get_response
    return callback(request, **param_dict)

  File "/home/espen/django/blog/apps/blog/views/", line 20, in details
    return HttpResponse(t.render(c))

  File "/usr/lib/python2.4/site-packages/django/core/", line 116, in render
    return self.nodelist.render(context)

  File "/usr/lib/python2.4/site-packages/django/core/", line 437, in render

  File "/usr/lib/python2.4/site-packages/django/core/", line 80, in render
    parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode)

IndexError: list index out of range

The template file that trys to extend base.html:

{% extends "base" %}

	{% block title %}
		Espen Grindhaug - Blog - {{ obj.headline }}
	{% endblock %}
	{% block content %}
		<h1>{{ obj.headline }}</h1>
		<p class="summary">{{ obj.summary }}</p>
		<p class="body">{{ obj.body }}</p>
		<p class="by">By {{ }} ({{ obj.pub_date }})</p>
	{% endblock %}

The weird thing here is that I get exactly the same error with completly different child template.

base.html (the same as in URL):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
    <link rel="stylesheet" href="style.css" />
    <title>{% block title %}Espen Grindhaug{% endblock %}</title>

    <div id="sidebar">
        {% block sidebar %}
            <li><a href="/">Home</a></li>
            <li><a href="/blog/">Blog</a></li>
        {% endblock %}

    <div id="content">
        {% block content %}{% endblock %}

The details function in that loads the template:

def details(request, slug):
		obj = entries.get_object(slug__exact=slug)
	except entries.EntryDoesNotExist:
		raise Http404
	t = template_loader.get_template('blog/details')
	c = Context(request, { 'obj':obj,})
	return HttpResponse(t.render(c))

Change History (9)

comment:1 Changed 11 years ago by adrian

Very strange. Is your base template called "base.html", and is it within your template root, rather than being in the "blogs" subdirectory of the template root?

comment:2 Changed 11 years ago by espen@…

  • Resolution set to fixed
  • Status changed from new to closed

The simple solution was to change {% extends "base" %} to {% extends "blog/base" %}

*a little bit ashamed* :/

comment:3 Changed 11 years ago by jacob

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Summary changed from IndexError when using {% extends "base" %} in template. to IndexError when using invalid {% extends %} in template should be replaced with better error message.

That error message is extremely unhelpful; I'm reopening this ticket and changing the title to indicate that we should fix the error message.

comment:4 Changed 11 years ago by adrian

  • milestone set to Version 1.0

comment:5 Changed 11 years ago by adrian

  • Status changed from reopened to new

comment:6 Changed 11 years ago by adrian

  • Status changed from new to assigned

comment:7 Changed 11 years ago by adrian

  • Resolution set to worksforme
  • Status changed from assigned to closed

I set about fixing this error message, but I can't reproduce it. I get a "Template 'base' cannot be extended, because it doesn't exist" message, which is expected behavior. Please reopen if you can reproduce the strange IndexError.

comment:8 Changed 11 years ago by espen@…

I can't reproduce it any more either.

comment:9 Changed 9 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top