On Sat, May 16, 2009 at 4:52 PM, Jon <joniama...@gmail.com> wrote:

>
>
> Hi all.
>
> I think django really rocks, but i have a question:
>
> I wrote a script in python that will get some values from servers and
> puts in them in a dictionary.
>
> The data is in the following format
> {'somehost': ['yes', '2'], 'remotehost': ['yes', '1'], 'localhost':
> ['yes', '1']}
>
> In python, i can then print the values as such:
> >>>       print "Server: "+server+" Version: "+serverlist[server][1]+"
> Reachable: "+serverlist[server][0]
> Server: somehost Version: 1 Reachable: no
> Server: remotehost Version: 2 Reachable: yes
> Server: localhost Version: 1 Reachable: yes
>
> In a django template however, this doesn't go far.
>
> The serverlist[server][0] type notation gives an error when used in a
> django template, so i tried this instead:
>
>      {% block status_table %}
>        {% for server in output_list %}
>          <tr>
>            <td><p class="server">{{ server }}</div></td>
>            {% for value in server %}
>              <td width="70px"><p class="server"> {{ value }} </p></
> td>
>            {% endfor %}
>          </tr>
>        {% endfor %}
>      {% endblock %}
>
> This prints each letter of the server name in different cell, which is
> not what i want.
> How can i retrieve the 'version' and 'reachable' values in the django
> template?
>
> Many thanks in advance.
>
> Jon
>
> >
>
You can do:

{% for server, data in status_table.iteritems %}
    {{ server }}: {{ data.0 }}, {{ data.1 }}
{% endfor %}

Which prints as:

somehost: yes, 2
remotehost: yes, 1
localhost: yes, 1

Alex


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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