如何在Django模板中获取键值? [英] How to get key value in django template?

查看:326
本文介绍了如何在Django模板中获取键值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django模板系统-如何从键中获取python字典值?

Django template system - how to get python dictionary value from key?

我有两个字典代表不同的数据,但是两个字典具有相同的键,因此我能够从同一键访问不同的数据。

I have two dictionaries which represent different data but both have same key so that I am able to access different data from the same key.

第一个格是:

{**'Papa, Joey C'**: {'Office Visit Est Pt Level 3 (99213)': 32, 'LAP VENTABD HERNIA
 REPAIR (49652)': 2, 'INSERT TUNNELED CV CATH (36561)': 4, 'Office Visit New Pt
Level 2 (99202)': 4, 'PUNCTURE/CLEAR LUNG (32420)': 1, 'REPAIR SUPERFICIAL WOUND
S (12011)': 1, 'DEBRIDE SKINTISSUE (11042)': 29, 'Office Visit New Pt Level 3 (9
9203)': 11, 'IDENTIFY SENTINEL NODE (38792)': 2, 'MAST MOD RAD (19307)': 1, 'EXC
 FACE LES SC < 2 CM (21011)': 1, 'ACTIVE WOUND CARE20 CM OR (97597)': 4, 'RPR UM
BIL HERN, REDUC > 5 YR (49585)': 3, 'REMOVE LESION BACK OR FLANK (21930)': 2}}

第二个字典是:

 {**'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}} 

在django模板上,我正在使用...

On django template, I am using...

{% for key1,value1 in mydict.items %}
<br><br>
<br><br>
<table border="1"><tr><td>Provider Name</td><td width="70%">{{key1}}</td></tr></table>
<br><br>
<table class="report_by_provider"><thead><tr><th>CPT Discription</th><th>Total</th></tr></thead>
<tbody>
{% for key2,val2 in value1.items %}
<tr>
<td>{{key2}}</td>
<td>{{val2}}</td>
</tr>
{% endfor %}
</tbody>
</table>

<table class="report_by_provider"><thead><tr><th>CPT Code</th><th>CPT Discription</th><th>Vol</th></tr></thead>
<tbody>

{% for key3,val3 in mydict1.key1%}
{% for key,val in val3.items %}
<tr>
<td>{{key1}}</td>
<td>{{val}}</td>
<td>{{val}}</td>
</tr>
{% endfor %}
{% endfor %}

但是第二个

推荐答案

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 %}

这篇关于如何在Django模板中获取键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆