I have a dictionary with tuples as keys. e.g.: {(‘tags’,’1′): ‘name’, (‘name’,’first’):’rik’, (‘name’,’last’):’atee’}
In django, how do I print the value at (‘name’,’first’), for example? I can do it with dict.items.1, or dict.items.2 – but ordering becomes an issue then.
The Django templating language is intentionally restrictive in what it allows you to reference.
For instance you must use the dot operator to access attributes AND dictionary elements which means the keys you reference must be strings.
From docs:
https://docs.djangoproject.com/en/dev/ref/templates/api/#variables-and-lookups
Your options are to either (a) use your view to munge the tuple-keys into a string-format or (b) you can use a different templating engine which allows you to reference with arbitrary keys.
Option (b) isn’t actually as bad as it sounds as their are templating languages for Django which are designed as a superset to Django’s templating language so (theoretically) all your old templates work and you just get more functionality. I advise you checkout the Jinja templating language, it has the functionality you’re looking for.