Hi Will,

When you do {{ site }}, it should follow the rules and print
str(ts_data[...]), which is probably not what you want.
A more pythonic way to do what you want:

{% for site in ts_data.items %}
  Site: {{ site.0 }}
  Rank: {{ site.1.rank }}
  ...

{% endfor %}


Cheers,
Mike Axiak

On May 3, 11:03 am, wj <[EMAIL PROTECTED]> wrote:
> Hey everyone,
>
> I am new to python and to django, but finally have a project that gives me a
> good excuse to learn both.  It has been a struggle as I come from the old
> school mod_perl web development world, from about 4-5 years ago.  I'm
> learning a lot and its been fun so far, but slow going.
>
> Right now, I have a small app, that queries the alexa top site information
> web service, parses the xml response and returns a dictionary of results
> with the site url as the keys.  The value for each URL is another dictionary
> of data, such as page rank, reach per million etc.  I'm having trouble
> drilling down through all the data using Django's template system.  I can
> iterate through the first set of keys fine, but have had no success getting
> down to the second level of data (rank, reach etc).   I'm probably
> overlooking something very simple, but so far its stumped me.
>
> The dict, looks something like this:
>
> ts_data = {
>  u'yahoo.com.cn': {'pageviews_per_million': u'1918.5',
>                    'pageviews_per_user': u'9.0',
>                    'rank': u'30',
>                    'reach_per_million': u'14340'},
>  u'yandex.ru': {'pageviews_per_million': u'1487.9',
>                 'pageviews_per_user': u'9.8',
>                 'rank': u'39',
>                 'reach_per_million': u'10250'},
>
> }
>
> Reading the template docs, I would have expected something like the
> following to work in the template, but it does not.  Where am I going wrong
> in my thinking?  The only thing that appears is the url (site).
>
> {% for site in ts_data %}
>   Site: {{ site }}
>   Rank: {{ site.rank }}
>   ....
>
> I have tried several other variations, trying to list all the data.  So far
> nothing has worked.
>
> In perl, using templating systems like Template Toolkit, I would generally
> arrange all my data into a big monolithic complex data structure before
> shipping it off to the template to be processed.  Is this the right approach
> for python and django?  Is there a more pythonic way to do this?
>
> Thanks for any help!
>
> -Will


--~--~---------~--~----~------------~-------~--~----~
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