it *should* be in the view anyway??? it's logic...
but it should be possible? Something like this would work...
although.. it's hideously innefficient.

{% for row in data %}
{% for key,val in row.items %}
{% for field in fields %}
{% ifequal field key %}
{{ key }}: {{ val }}
{% endifequal %}
{% endfor %}
{% endfor %}
{% endfor %}

To iterate a dictionary by Key and Value in the template.. you need to
iterate on .items :)

- alex

On Feb 3, 1:45 am, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> I'm not sure there's a way to do this purely in the template language.  
> You can munge the data in the view instead.  This line creates a new
> filtered_data list that has only the data you want to display:
>
> filtered_data = [ dict([ (k,d[k]) for k in fields ]) for d in data ]
>
> --Ned.http://nedbatchelder.com/blog
>
>
>
> Michael Hipp wrote:
> > I'm trying to do something with a template that I thought would be very
> > simple but I've not yet found a way to make it work at all.
>
> > from django.template import Template, Context
> > fields = ("f1", "f3")
> > data = [
> >      {"f1": "Foo", "f2": "Skip  ","f3": "Bar"},
> >      {"f1": "Cat", "f2": "Ignore","f3": "Dog"},
> >      {"f1": "Him", "f2": "Avoid ","f3": "Her"},
> > ]
> > t = Template("""
> >      {% for row in data %}
> >          {% for f in fields %}
> >              {{ row.f }}
> >          {% endfor %}
> >      {% endfor %}
> >   """)
> > print t.render(Context({'fields': fields, 'data': data}))
>
> > I want to print out the data items row-by-row but skipping 'f2' since
> > it's not listed in 'fields'. The above is how it seems like it ought to
> > work, but it just ignores me. Lots of other crazy permutations didn't
> > work either.
>
> > Can someone show me what (very simple) thing I'm missing?
>
> > Thanks,
> > Michael
>
> --
> Ned Batchelder,http://nedbatchelder.com
--~--~---------~--~----~------------~-------~--~----~
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