67👍
mydict = {'Papa, Joey C': {'10140': 1, '10061': 1, '99214': 1, '99215': 1, '12011': 1, '97606': 1, '49080': 1, '10120': 1, '49440': 1, '49570': 1}, 'Bull, Sherman M': {'99211': 1, '99214': 1, '99215': 1, '99231': 1, '99236': 1, '12051': 1, '15004':1, '47100': 1, '15430': 1, '15431': 1}}
{% for mykey,myvalue in mydict.items %}
{{ mykey }} : {{ myvalue }}
{% endfor %}
12👍
Given the dictionary:
{'papa': {'name': 'Papa, Joey C', 'values': {'10140': 1, ...
you can access the values from the keys using {{ mydict1.papa.name }}
Knowing directly use the key in the template if it contains use spaces or specials chars, you could either change your structure (like i just did for the example) or create a custom templatetag/filter which you could use like {{ mydict1|get_key:"Papa, Joey C"}}
.
If you want a complete example for a filter just let me know.
- [Django]-Django – cannot import name 'config' from 'decouple'
- [Django]-How to check whether the user is anonymous or not in Django?
- [Django]-Django REST framework – limited queryset for nested ModelSerializer?
1👍
dic_1
is a dictionary. i need the key and value.
we can do loop and get the key and value like this.
{% for key, value in dic_1.items %}
{{key}}
{{value}}
{% endfor %}
- [Django]-Django Call Class based view from another class based view
- [Django]-How does django know which migrations have been run?
- [Django]-How to clear the whole cache when using django's page_cache decorator?
Source:stackexchange.com