Opened 7 years ago

Closed 7 years ago

#6558 closed (fixed)

Need a better error message when inheriting from empty template

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

Description (last modified by ramiro)

If you inherit from a template with no blocks (for instance containing just the text "Hello"), you get the following error message:

"Caught an exception while rendering: list index out of range"

I don't know what is supposed to happen, or if this is supposed to be allowed, but it would at least be way better to have an error like "There are no blocks in the template foo."

This happens when it's traversing the nodes in the inherited template while rendering, and finds only a TextNode and no block nodes. I don't really know what the code here is trying to do.

Here's the traceback. In my code, "base.html" is the template that says "hello".

----

Environment:

Request Method: GET
Request URL: http://localhost:8081/pubs/
Django Version: 0.97-pre-SVN-7092
Python Version: 2.5.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'dubweb.polls',
 'dubweb.pubs',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Template error:
In template /Users/toomim/projects/dubweb/dubweb/templates/pubs/index.html, error at line 1
   Caught an exception while rendering: list index out of range
   1 :  {% extends "pubs/base.html" %} 
   2 : 
   3 : {% block middlecontent %}
   4 : {% if venue_list %}
   5 : <ul>
   6 :   {% for venue in venue_list %}
   7 :   <li>Featured at {{ venue }}</li>
   8 :   <ul>
   9 :     {% for pub in venue.pub_set.all %}
   10 :     
   11 :     <li><b>{{ pub.title }}</b>


Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  73.         while isinstance(compiled_parent.nodelist[pos], TextNode):

Exception Type: IndexError at /pubs/
Exception Value: list index out of range

Change History (6)

comment:1 Changed 7 years ago by anonymous

  • Cc oliver@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by ubernostrum

#6968 as a duplicate, but had a suggestion for code to solve the issue.

comment:3 Changed 7 years ago by jacob

  • Summary changed from Need error message when inheriting from empty template to Need a better error message when inheriting from empty template
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 7 years ago by ramiro

  • Description modified (diff)

comment:5 Changed 7 years ago by ajs

I can't duplicate this on r7732.
I have the templates:

customers/layout2.html

Hello!!

customers/customer_index.html:

{% extends "customers/layout2.html" %}
{% block content %}
Some content!!!
{% endblock %}

and the output is:

Hello!!

comment:6 Changed 7 years ago by Karen Tracey <kmtracey@…>

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

Looks like this was fixed by #7318 (r7688).

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