On Wed, Mar 21, 2012 at 7:53 AM, James <[email protected]> wrote: > > > On Wednesday, March 21, 2012 8:47:23 AM UTC-4, [email protected] wrote: >> >> This is probably a stupid newbie question .... >> >> I want to access a column of data in a row using forloop.counter, but >> I cannot get it to work. >> >> In my test code, if I display {{ forloop.counter }} I get 2 >> If I display {{ headers.0.2 }} I get ToolType >> But if I display {{ headers.0.forloop.counter }} I get nothing >> >> What is the proper syntax for this? > > > the forloop.counter and friends will simply give you information about the > iteration, it won't give you any information about the data in the queryset
Yes, I realize that. I am using it withing a loop to try an access a specific item of data. The code I showed was just an example from one iteration of the loop. > (I'm assuming this is what you mean when you say column). > > Here are the > docs https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for > > If you want to access the column of data, assuming it's referenced from a > model, just the attribute of that model. If you passed in a list to the > template, you just use the django "dot" look-up syntax. Perhaps my question wasn't clear. I have a list called headers. From within a for loop I want the n'th item from the first row. In the loop I am trying to access {{ headers.0.forloop.counter }} but I get no value from that. But if I hard code the number (as a test), e.g.: {{ headers.0.2 }} then I do get the value. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

