Use variable as dictionary key in Django template

Create a template tag like this (in yourproject/templatetags):

@register.filter
def keyvalue(dict, key):    
    return dict[key]

Usage:

{{dictionary|keyvalue:key_variable}}

Leave a Comment