Programming

Django templates: Accessing dict keys with colons

Earlier this week I was updating a dashboard which uses Django templates. The data included a Python dictionary with a key that contains a colon: data:foo. Normally the dictionary item is accessed using dotted notation such as {{ mydict.foo }} but using a colon results in a syntax error. Exception Type: TemplateSyntaxError Exception Value: Could not parse the remainder: ':foo' from 'mydict.data:foo' The simple fix is to change the key but I don’t own this object and it cannot be easily changed.