Template syntax issues w dict

22 views
Skip to first unread message

Lachlan Musicman

unread,
May 1, 2015, 3:22:47 AM5/1/15
to django...@googlegroups.com

Hola,

Django shell gives right results, template doesn't: code here

http://dpaste.com/1NJEKD8

What am I doing wrong?

L.

ADEWALE ADISA

unread,
May 1, 2015, 3:48:25 AM5/1/15
to django...@googlegroups.com

If I can understand your code, of seems you want a table of : Institution | Number of attendees
So if am right u can achive it this way :

{% for org, num in attendees_per_org.items() %}
            <tr>
                <td>{{ org }}</td>
                <td>{{ num }}</td>
            </tr>
  {% endfor %}

Since your dataset is a dictionary, u need to use key,value to get elements in both side. Also items() is also required.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiN78i37JA9UJov7%2BAVbJzRt4c5YCX3em2XvN-QmefxSvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Lachlan Musicman

unread,
May 1, 2015, 7:28:54 PM5/1/15
to django...@googlegroups.com

<wince> .items

Damn.

Thanks

Bernardo Brik

unread,
May 2, 2015, 4:24:22 PM5/2/15
to django...@googlegroups.com
just a small correction – lose the parens after items:
{% for org, num in attendees_per_org.items %}
Reply all
Reply to author
Forward
0 new messages