#9290 closed (worksforme)
List index out of range when invalid template tag is used
| Reported by: | aneil | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 1.0 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Using an invalid template tag results in the generic 'list index out of range' error which doesn't show any information about the offending file or expression. E.g., if a template contains:
...
{% invalid_template_tag %}
...
An error occurs at line 279 of django.template.__init__.py:
278 try: 279 compiled_result = compile_func(self, token) 280 except KeyError: 281 self.invalid_block_tag(token, command) 282 except TemplateSyntaxError, e: 283 if not self.compile_function_error(token,e): 291 raise
What seems to be happening is that self.invalid_block_tag(...) raises an error which gets caught by TemplateSyntaxError and which eventually leads to the generic 'list index out of range' error being reported in the Django error page.
This problem has also been reported to the BetterErrorMessages page.
Change History (2)
comment:1 by , 17 years ago
| Needs documentation: | set |
|---|---|
| Resolution: | → worksforme |
| Status: | new → closed |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
If the original reporter can still repeat this, please reopen, but include a short, complete template which demonstrates the problem and the full traceback that Django displays at the time (use the cut-and-paste view when copying the traceback). It's not clear from reading the code where the index error could be coming from and badri's example above shows that the simplest case doesn't trigger the problem. So if there's a generic error here, we need a lot more information to be able to replicate it.
>>> from django import template >>> s = u'<html> <h1>{% badri %} </h1></html>' >>> t = template.Template(s) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 166, in __init__ self.nodelist = compile_string(template_string, origin) File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 187, in compile_string return parser.parse() File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 281, in parse self.invalid_block_tag(token, command) File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 333, in invalid_block_tag raise self.error(token, "Invalid block tag: '%s'" % command) django.template.TemplateSyntaxError: Invalid block tag: 'badri'