Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Iterating over dictionaries in template not working in Django 1.2.3 [RSS Feed]

#1 Jan. 6, 2011 18:37:43

jeff a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Iterating over dictionaries in template not working in Django 1.2.3


I'm trying to create a page for mass user creation, and I'm having
troubles iterating over the error dictionaries in the template. The
dictionary I am trying to iterate over looks like this:

{'username': }

But rather than iterating over this single item, the for loop in the
template jumps right to the {% empty %} tag, despite the dictionary
clearly having items in it.

Here's what is in the view:

46 try:
47 u.full_clean()
48 u.save()
49 except ValidationError, e:
50 unsaved_users.append()

Where u is a User object

Here's what is in the template:

9 {% for user, errors in unsaved_users %}
10 {{ user }} was not saved:
11 <ul>
12 {% for key,value in errors.items %}
13 <li>{{ key }}: {{ value }}</li>
14 {% empty %}
15 <li>Django thinks I'm empty...</li>
16 {% endfor %}
17 </ul>
18 {% endfor %}

Any idea what's going on here? The only thing I can come up with is
that the template language can't handle nested search of a list and
then a dictionary.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 6, 2011 21:32:42

jeff a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Iterating over dictionaries in template not working in Django 1.2.3


I've solved the issue. The problem is that I was trying to iterate
over a ValidationError instead of it's message_dict. The changed code
for the view is below:

>  46                     try:
>  47                         u.full_clean()
>  48                         u.save()
>  49                     except ValidationError, e:
>  50                         unsaved_users.append()

On Jan 6, 11:58 am, jeff aigner <enumerat...@gmail.com> wrote:
> I'm trying to create a page for mass user creation, and I'm having
> troubles iterating over the error dictionaries in the template. The
> dictionary I am trying to iterate over looks like this:
>
> {'username': }
>
> But rather than iterating over this single item, the for loop in the
> template jumps right to the {% empty %} tag, despite the dictionary
> clearly having items in it.
>
> Here's what is in the view:
>
>  46                     try:
>  47                         u.full_clean()
>  48                         u.save()
>  49                     except ValidationError, e:
>  50                         unsaved_users.append()
>
> Where u is a User object
>
> Here's what is in the template:
>
>  9 {% for user, errors in unsaved_users %}
>  10 {{ user }} was not saved:
>  11     <ul>
>  12         {% for key,value in errors.items %}
>  13             <li>{{ key }}: {{ value }}</li>
>  14         {% empty %}
>  15             <li>Django thinks I'm empty...</li>
>  16         {% endfor %}
>  17     </ul>
>  18 {% endfor %}
>
> Any idea what's going on here? The only thing I can come up with is
> that the template language can't handle nested search of a list and
> then a dictionary.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Iterating over dictionaries in template not working in Django 1.2.3 [RSS Feed]

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support