#23114 closed Bug (fixed)
Template Variables Docs Incorrect/Unclear
Reported by: | Owned by: | Gabriel Muñumel | |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | template |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
On this section https://docs.djangoproject.com/en/1.6/topics/templates/#variables
In the "Behind the Scenes" section, it gives the order that Django tries to resolve a variable like "X.Y".
The 4 things that it tries are accurate, but the way/order they're done doesn't appear to be correct.
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.
Change History (10)
comment:1 by , 10 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
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.
comment:4 by , 10 years ago
So I guess I'm saying there are 2 issues:
- The Attribute lookup vs Method call thing.
- 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.
comment:7 by , 10 years ago
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.
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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