Skip to content
Myr

update wording on dictionary default ordering

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by jeff · committed by David Lord · parent 4abb2a0 · Browse files · 2 files+13 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−6 removed

  • other:+13 added−6 removed

2 files+13 added−6 removed

modified:docs/templates.rst+11 added-3 removed
686 unmodified lines
687 <dd>{{ value|e }}</dd>688 {% endfor %}689 </dl>690691Note, however, that **Python dicts are not ordered**; so you might want to692either pass a sorted ``list`` of ``tuple`` s -- or a693``collections.OrderedDict`` -- to the template, or use the `dictsort` filter.691Python dicts may not be in the order you want to display them in. If692order matters, use the ``|dictsort`` filter.693694.. code-block:: jinja695696 <dl>697 {% for key, value in my_dict | dictsort %}698 <dt>{{ key|e }}</dt>699 <dd>{{ value|e }}</dd>700 {% endfor %}701 </dl>702703Inside of a for-loop block, you can access some special variables:704705+-----------------------+---------------------------------------------------+706| Variable | Description |
1169 unmodified lines
modified:src/jinja2/filters.py+2 added-3 removed
305 unmodified lines
306 case_sensitive: bool = False,307 by: 'te.Literal["key", "value"]' = "key",308 reverse: bool = False,309) -> "t.List[t.Tuple[K, V]]":310 """Sort a dict and yield (key, value) pairs. Because python dicts are311 unsorted you may want to use this function to order them by either312 key or value:310 """Sort a dict and yield (key, value) pairs. Python dicts may not311 be in the order you want to display them in, so sort them first.312313 .. sourcecode:: jinja314315 {% for key, value in mydict|dictsort %}
1293 unmodified lines