Access dict value in template using variable as key

Within a template, how do I access a dictionary value by specifying a key that is stored in a variable?

If I have a dictionary e.g.

eventEntriesDict	
{1: 'A',
 2: 'B',
 3: 'C',
 4: 'D',}

I can access any value from within the template by:

{{ eventEntriesDict.2 }}

This returns the expected value of B

What I would like to do however is

{% with myid = query.field.id %}
{{ eventEntriesDict.myid }}
{% endwith %}

If I try this I don’t get anything returned.

I’d be grateful for advice on where I’m going wrong.

Many thanks

You’re not doing anything wrong. The Django template language is not designed to handle that.

You need to either reorganize your data in the view, create a custom filter, or create a custom model method to it.