On Thu, Apr 9, 2009 at 3:23 PM, Walt <[email protected]> wrote: > > After extensive searching, I'm still unable to find a way to reference > individual items in a list without using a for loop. > > For example, I have this basic code in my views.py: > > project_list = Project.objects.all().order_by('-id')[:6] > > t = loader.get_template('portfolio/index.php') > c = Context({ > 'project_list' : project_list, > }) > > Now, in my template file I want to be able reference the six > different elements in the list directly, without having to loop > through them. How can I do this? > > I've tried project_list[1] but that just errors out. > > Thanks, > Walt > > -~ > > > >
The default "dot" lookup works with array indices, so you can do project_list.1 project_list.2, etc. From: http://docs.djangoproject.com/en/dev/ref/templates/api/#rendering-a-context Colin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

