18👍
✅
The filter you want is something like
@register.filter(name='getkey')
def getkey(value, arg):
return value[arg]
And used with
{{test|getkey:'this works'}}
source: http://www.bhphp.com/blog4.php/2009/08/17/django-templates-and-dictionaries
👤Ross
2👍
I don’t know any standard solution in Django. I think it is possible with a template filter.
You may be interested by this article http://push.cx/2007/django-template-tag-for-dictionary-access (the author is using template tag term but in fact it is a template filter)
I hope it helps
👤luc
- Django's HttpResponseRedirect is http instead of https
- Cannot install "psycopg2" on Windows 10 with Python 3.8
- Django – links generated with {% url %} – how to make them secure?
-4👍
That doesn’t look right to me. Can you do the following?
{{ test['works'] }}
{{ test['this fails'] }}
This is how dictionary access in python typically works.
Source:stackexchange.com