Ref the code that does this:
https://github.com/django/django/blob/master/django/template/base.py#L756
What actually (seems to) happen is:
* Try dictionary lookup to get "thing"
* If not found "thing", try attribute lookup to get "thing"
* If not found "thing", try list-index lookup to get "thing"
* If not found "thing", then fail
* If "thing" is callable, then "thing" = "thing()"
* Return "thing"
Applies in version 1.6 and onwards, probably applicable to older doc
versions too.
--
Ticket URL: <https://code.djangoproject.com/ticket/23114>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* easy: 0 => 1
* needs_tests: => 0
* needs_docs: => 0
Comment:
Hi,
It seems this list has remained largely unchanged since its initial
introduction (096ad32c845f850278b942d087e607dc4311b5f9).
I don't see a reason to distinguish argument lookups and method calls. I
think we could simply merge the two items into one: "Attribute/method
lookup".
THanks
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:1>
* owner: nobody => gmunumel
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:2>
Comment (by anonymous):
Even that's not quite accurate, since it tries the initial lookup (dict
then attribute then list index). Once it's got that value, it then calls
it if possible.
So maybe the docs should say something like:
Value lookup is done in the following order:
* dict-key
* attribute
* list-index
If the value is callable, it is called, and the value becomes the result
of that call.
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:3>
Comment (by tom.dalton@…):
So I guess I'm saying there are 2 issues:
1. The Attribute lookup vs Method call thing.
2. It's not stated that other values (e.g. if dictionary or list lookup
worked) are actually called. The docs imply only methods are called.
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:4>
Comment (by bmispelon):
Yes, good point.
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:5>
Comment (by gmunumel):
Here is the pull request [https://github.com/django/django/pull/2994].
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:6>
Comment (by anonymous):
Thanks for that. I added a comment to the pull request with a patch for a
slightly more comprehensive rework to include the stuff talked about
enough. I don't think that just combining attribute/method lookup is
enough to clarify what Django actually does behind the scenes.
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"62c74abbb06a081708c2cb5cc459f39beb26acaa"]:
{{{
#!CommitTicketReference repository=""
revision="62c74abbb06a081708c2cb5cc459f39beb26acaa"
Fixed #23114 -- Clarified documentation of template lookups.
Thanks to gmunumel and Tom Dalton for their help on the patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:8>
Comment (by Baptiste Mispelon <bmispelon@…>):
In [changeset:"13d44f54a265e9fc6185e1d5518da8ad568fbaad"]:
{{{
#!CommitTicketReference repository=""
revision="13d44f54a265e9fc6185e1d5518da8ad568fbaad"
[1.7.x] Fixed #23114 -- Clarified documentation of template lookups.
Thanks to gmunumel and Tom Dalton for their help on the patch.
Backport of 62c74abbb06a081708c2cb5cc459f39beb26acaa from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:9>
Comment (by anonymous):
Thanks for the speedy resolution!
--
Ticket URL: <https://code.djangoproject.com/ticket/23114#comment:10>