Opened 11 years ago

Closed 11 years ago

#8976 closed (invalid)

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

Reported by: Hector Lecuanda 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: no UI/UX: no


When unpacking key: value pairs in a dict, in a foor loop, as documented in , x gets the first character of key, y gets the second character of key.

Template Code:


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



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

    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


Change History (1)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top