Hi,

I'm a newbie and am having a an issue accessing the attribute for a
variable.  I did a search (django documentation and here) and found
nothing. If this has been covered before, please direct me to the
correct thread.

I currently pass a context to my template and it works fine. For
example, I can do:

{% for s in objectlist %}
  User name is: {{s.user_name}}
{% endfor %}

But, I can't do this:
User name is: {{ objectlist.0.user_name }}

What I'm trying to do is access the first user in the list and then
access the user_name attribute for that user.  BTW, {{objectlist.0}}
does work.

My current solution is to return the first user (first item in the
objectlist) as part of the context like this:

  return render_to_response('app/apptemplate.html",{'objectlist'}:
objectlist, 'firstobject':objectlist[0]})

However, this seems counter-intuitive. I should be able to just
explicitly grab the first item and access it's attributes in the
template.

Is there  a better way? How do I do this?
Thanks,
Hani


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to