Opened 17 years ago
Last modified 16 years ago
#6558 closed
Need a better error message when inheriting from empty template — at Version 4
Reported by: | toomim | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | ||
Cc: | oliver@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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 (4)
comment:1 by , 17 years ago
Cc: | added |
---|
comment:2 by , 17 years ago
comment:3 by , 16 years ago
Summary: | Need error message when inheriting from empty template → Need a better error message when inheriting from empty template |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 16 years ago
Description: | modified (diff) |
---|
#6968 as a duplicate, but had a suggestion for code to solve the issue.