Suppose I've a dict like:
dic = {'1': 'string', 1 :'integer'}
When I pass it to a django template and try to access dic.1
then it always returns 'string'
.
If I remove the key '1'
, then dic.1
returns 'integer'
.
I know I can use a custom tag for this, something like:
from django import template
register = template.Library()
@register.filter
def get_key(value, arg):
return value.get(arg, None)
Then {{ dic|get_key:1 }}
works fine.
But, is there a way to directly access the integer/float keys without using a custom tag?