I recommend you do a custom filter Create a module in your app that is called templatetags
and inside a file for your custom filters and labels, as indicated in the documentation.
In your filter file add this code:
@register.filter(name='clave')
def clave(dicc, key):
try: return dicc[key]
except KeyError: return 0
The filter acts on your dictionary and clave
is the key. Since you do not provide a minimum, complete and verifiable example I'll give you a generic example.
{% for nombre in nombres %}
Diccionario: {{ dicc | clave: nombre }}
{% endfor %}
Like any filter in Django, you can nest them and use it with other filters, for example, I use it like this:
{{pivot|clave:t|clave:'mini'|money}}
To convert this:
{'ejer': Decimal('152675.00'),
'label': 'January de 2014',
'mini': Decimal('159793.56'),
'porc': '95.55',
'rein': Decimal('0.00'),
'sald': Decimal('7118.56')}
on something like this: