﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24284	List-index lookup in templates does not function as advertised	Matt Kahl	nobody	"In the Django template language docs (https://docs.djangoproject.com/en/1.6/ref/templates/api/) the list-index lookup syntax is advertised as {{{list[index]}}} but a {{{TemplateSyntaxError}}} is thrown when using that syntax. The example provided shows {{{list.index}}} which, while arguably less intuitive, does work.

{{{#!python
>>> from django.template import Template, Context
>>> Template(""The first element is {{ items[0] }}"").render(Context({""items"":[""spam""]}))
Traceback (most recent call last):
  File ""<input>"", line 1, in <module>
  File ""/Users/mattkahl/.venvs/sp_web/lib/python2.7/site-packages/django/template/base.py"", line 125, in __init__
    self.nodelist = compile_string(template_string, origin)
  File ""/Users/mattkahl/.venvs/sp_web/lib/python2.7/site-packages/django/template/base.py"", line 153, in compile_string
    return parser.parse()
  File ""/Users/mattkahl/.venvs/sp_web/lib/python2.7/site-packages/django/template/base.py"", line 254, in parse
    filter_expression = self.compile_filter(token.contents)
  File ""/Users/mattkahl/.venvs/sp_web/lib/python2.7/site-packages/django/template/base.py"", line 360, in compile_filter
    return FilterExpression(token, self)
  File ""/Users/mattkahl/.venvs/sp_web/lib/python2.7/site-packages/django/template/base.py"", line 577, in __init__
    ""from '%s'"" % (token[upto:], token))
TemplateSyntaxError: Could not parse the remainder: '[0]' from 'items[0]'
>>> Template(""The first element is {{ items.0 }}"").render(Context({""items"":[""spam""]}))
u'The first element is spam'
}}}

Tested in 1.6. The {{{list[index]}}} syntax is referenced all the way back to the 1.3 docs.

This is either a feature request, a bug report, or a documentation error."	Cleanup/optimization	closed	Documentation	1.6	Normal	invalid			Unreviewed	0	0	0	0	0	0
