#24284: List-index lookup does not function as advertised
--------------------------------------+--------------------
     Reporter:  mattkahl              |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Documentation         |    Version:  1.6
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/24284>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.975fbebeeab5820080be1414eb12aee6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to