#15265 closed (wontfix)
Problem with "__call__" method in Templates
Reported by: | Stephane | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.3-beta |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
We have another problem in templates since Django 1.3 when we put dict values into template with "getitem".
We create this class for example:
class MyDict(object):
TEST = {"var": "test", "meuh": "test2"}
def getitem(self, key):
"""
Retrieves a value. Raises a :exc:KeyError
if *key* does not exists.
"""
return MyDict.TEST[key]
def call(self, kwargs):
"""
Puts one or more values into this...
"""
for key, value in kwargs.items():
self[key] = value
We add this in a template context:
test = MyDict()
return test
In the template, we want to get the value of "var" key for example:
{{mydict.var}}
No output... But if we remove "call" method, we have the value: "test" (same as before 1.3).
Best regards,
Stephane
Change History (4)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This is most likely a "won't fix". See ticket #15025 and the docs for render. Citing:
If any part of the variable is callable, the template system will try calling it.
Changed in Django Development version: Previously, only variables that originated with an attribute lookup would be called by the template system. This change was made for consistency across lookup types.
Sorry, underscores are removed...