On the other hand a paragraph about defaultdict on
[https://docs.djangoproject.com/en/1.8/ref/templates/language/#variables
another page] suggests using dict instead of defaultdict. But while it
solves the problem of creating an entry by making a lookup it doesn't
solve the problem of "items" key within a dictionary.
I thought that maybe one or both pages could contain a reminder that the
view author should remember not to pass a dictionary with the "items" key
if the template author wants to use that "for key, value" construct.
--
Ticket URL: <https://code.djangoproject.com/ticket/25574>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:1>
* owner: nobody => jbzdak
* status: new => assigned
Comment:
If this is OK (I don't really know what is the protocol) I'll do this
issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:2>
* has_patch: 0 => 1
Comment:
Here is the PR link: https://github.com/django/django/pull/5450.
Here is full wording (maybe a bit verbose):
{{{
Keep in mind that ``items`` key in a dictionary will shadow
``items()``
function. This lookup order can cause some unexpected behavior.
In normal situations Django template expression ``{{ data.items }}``
will
return result of following python code: ``data.items()``, however if
``data`` dictionary will contain ``items`` key, the same django
expression
will return: ``data['items']``, which is most probably *not what you
want*.
You should avoid adding dictionary entries whose keys are named like
methods
of dictionary instance for example: ``items``, ``values``, ``keys``,
to
dictionaries that will be passed to Django templates.
For additional information see
:ref:`documentation of template variables <template-variables>`.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"32cd7069711d2e02fcd20c005c59c175d542c62e" 32cd706]:
{{{
#!CommitTicketReference repository=""
revision="32cd7069711d2e02fcd20c005c59c175d542c62e"
Fixed #25574 -- Documented {{ dict.items }} shadowing in for template tag
docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"5a9e93e05423c176adfef714f804fe80e6fbb522" 5a9e93e0]:
{{{
#!CommitTicketReference repository=""
revision="5a9e93e05423c176adfef714f804fe80e6fbb522"
[1.9.x] Fixed #25574 -- Documented {{ dict.items }} shadowing in for
template tag docs.
Backport of 32cd7069711d2e02fcd20c005c59c175d542c62e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"3e8234b77e2698d14a7825319845e5038424f09d" 3e8234b]:
{{{
#!CommitTicketReference repository=""
revision="3e8234b77e2698d14a7825319845e5038424f09d"
[1.8.x] Fixed #25574 -- Documented {{ dict.items }} shadowing in for
template tag docs.
Backport of 32cd7069711d2e02fcd20c005c59c175d542c62e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25574#comment:6>