On Thu, Aug 26, 2010 at 4:17 PM, Andrea Imparato
<imparato.and...@gmail.com> wrote:
>
> I have 2 lists and I have to scan them "concurrently" with the same
> indexes at the same time. Something like:
>
> {% for lists %}
> first item from the first list
> first item from the second list
> {% endfor %}
>
> I thought about creating something like a map with 2 values in each
> index but I don't know how to use it in the template.
>
> Any advice?:)
>

Figure out the data structures you need in your view, pass them to
your template in the context.

For instance

import itertools

names = [ 'Bob', 'Jim', 'Jane' ]
ages = [ 24, 17, 37 ]

ctxt = RequestContext(request, {
  'names_and_ages': itertools.izip(names, ages),
  })

return render_to_response('my_template.html', context_instance=ctxt)

{% for tuple in names_and_ages %}
Hello {{ tuple.0 }}, you are {{ tuple.1 }} yrs old.
{% endfor %}

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to