Saturday, November 21, 2009

Django : passing list of objects to template

in views.py:

object_list = [obj0, obj1, obj2]
context = {'object_list' : object_list }
return direct_to_template(request, 'path_to_template.htm', extra_context = context)
in path_to_template.htm:

{{ object_list.0.attrib }} #access to obj0.attrib  
{{ object_list.2.attrib }} #access to obj2.attrib 
etc.

No comments:

Post a Comment