#1903 closed enhancement (invalid)
[patch] to add filter "get" to add getting data from dicts and lists
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Any chance this could be added? I want to display a list of items with user customizable columns. I couldn't see any other way to do this other than implementing a filter. It seems like it would be a fairly fundamental filter, but it's absent from the library ("slice" isn't appropriate as dicts don't play nice with them). An alternative, of course, would be to have "getitem" and "getattr" filter, but that's slightly more verbose and technical. Any chance this could be added? Thanks.
-e
Attachments (2)
Change History (4)
by , 19 years ago
comment:1 by , 19 years ago
Summary: | patch to add filter "get" to add getting data from dicts and lists → [patch] to add filter "get" to add getting data from dicts and lists |
---|
fixing the summary
by , 19 years ago
Attachment: | get-patch.diff added |
---|
adding the .diff extension to get highlighting working
comment:2 by , 19 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Your patch seems to do exactly the same as {{ data.a }} does in a template (if data
is a dictionary, this will retrieve data['a']
). If this is not what you want to happen, then please reopen with a more concrete example (showing how this would act in a template; the test cases you include are not completely clear, except to make me think it acts like something we already have).
If you want something that can dereference the value of template variable "a" to get the real value to look up in the dictionary (i.e. if {{a}} is "b", it looks up data['b']
), we have traditionally avoided adding features like this to Django's templating language in order to keep it as simple as possible. The justification is that you should extract the data you really need in the view function and pass it in, rather than doing the programming in the template.
patch to add feature