Code

Opened 6 years ago

Closed 6 years ago

#8976 closed (invalid)

{% for x, y in dictionary %} not working as documented

Reported by: hlecuanda Owned by: nobody
Component: Template system Version: 1.0
Severity: Keywords: for loop dictionary
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When unpacking key: value pairs in a dict, in a foor loop, as documented in http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ttag-for , x gets the first character of key, y gets the second character of key.

Template Code:

{{django_version}}

Image Sizes: {{ insert_image_sizes|pprint }}

{% for compartment,inserts in insert_image_sizes %}
    compartment: {{ compartment|pprint }}
    inserts: {{inserts}}
{% endfor  %}
insert_image_sizes.101.aaaa.1:{{ insert_image_sizes.101.aaaa.1}}
insert_image_sizes.1.1.1:{{ insert_image_sizes.1.1.1}}

Output:

1.0-final-SVN-8985

Image Sizes: {u'-': {},
 u'101': {u'aaaa': (92, 169), u'bbb': (91, 169)},
 u'102': {u'cccc': (53, 98), u'dddd': (53, 98)},
 u'103': {},
 u'104': {},
 u'105': {}}


    compartment: u'-'
    inserts: 

    compartment: u'1'
    inserts: 0

    compartment: u'1'
    inserts: 0

    compartment: u'1'
    inserts: 0

    compartment: u'1'
    inserts: 0

    compartment: u'1'
    inserts: 0

insert_image_sizes.101.aaaa.1:169
insert_image_sizes.1.1.1:

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Re-read that piece of documentation you referred to. You'll notice that it says you need to loop over my_dict.items for dictionaries.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.