Oops, I totally missed that 'test' was a dictionary. This should work
then:

{% for key, x in posts.items %}
<h2><a href="#">{{ x.title }}</a></h2>
<br>
<br>
<p>{{ x.post }}</p>
{% endfor %}

Alternately, if your keys are just going to be sequential integers,
you could just put this stuff into a list and use my first suggestion.

On Jun 17, 3:41 pm, "Juan Hernandez" <[EMAIL PROTECTED]> wrote:
> it does not return any values.
>
> I did post.0.title because the dictionary is established like this:
>
> >>> test
>
> {0: {'post': 'My First Post', 'title': 'My First Title'}, 1: {'post': 'My
> Second Post', 'title': 'My Second Title'}}
>
> and it goes on and on
>
> If I could iterate over it, like post.0.title, then post.1.title and so
> forth, it would be perfect
>
> Thanks for your help
>
> On Wed, Jun 18, 2008 at 2:42 PM, Joel Bernstein <[EMAIL PROTECTED]> wrote:
>
> > I could be completely mistaken, but can't you replace 'post.0.title'
> > and 'post.0.post' with 'x.title' and 'x.post', respectively?
>
> > On Jun 17, 1:50 pm, "Juan Hernandez" <[EMAIL PROTECTED]> wrote:
> > > Hey there
>
> > > I've been practicing for a while with the template system and I have some
> > > questions:
>
> > > Lets say that I create this dictionary:
>
> > > test = dict()
> > > test[0] = {'title': 'My First Title', 'post': 'My First Post'}
> > > test[1] = {'title': 'My Second Title', 'post': 'My Second Post'}
> > > etc... til 10 for example
>
> > > If i want to display that information, the best way would be to iterate
> > over
> > > each number and show 'title' and 'post'.
>
> > > My question is: How can I actually iterate over a dictionary like this
> > > inside a template? If i do this (assuming that the shown dictionary has
> > been
> > > assigned to 'post' in render_to_response)
>
> > > {% for x in post%}
> > > <h2><a href="#">{{ post.0.title }}</a></h2>^M
> > > <br>
> > > <br>
> > >        <p>{{ post.0.post }}</p>^M
>
> > > It will only show the first part of the dictionary and 'x' as a number
> > > cannot be handled. I haven't found a way to have an increasing number to
> > > iterate with... Something to replace the zero that increases until is
> > > finished by hte condition
>
> > > What would be the best way to display the whole dictionary in a
> > template??
>
> > > Thank you very much as usual
> > > jhv
--~--~---------~--~----~------------~-------~--~----~
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