[Solved]-Dict keys with spaces in Django templates


The filter you want is something like

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



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



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.

Leave a comment