Opened 17 years ago
Closed 17 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 |
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:
Note:
See TracTickets
for help on using tickets.
Re-read that piece of documentation you referred to. You'll notice that it says you need to loop over
my_dict.itemsfor dictionaries.