码迷,mamicode.com
首页 > 其他好文 > 详细

前端循环字典的方式

时间:2018-04-29 17:49:25      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:val   har   index   blank   html   ret   turn   charset   信息   

index.html

 {{ user_dict.k1 }}
    <ul>
        {% for k,row in user_dict.items %}
            <li><a  target="_blank"  href="/CC/detail/?nid={{ k}}">{{ row.name }}</a></li>
        {% endfor %}
    </ul>
    <p>_______________________________________________________</p>
    <ul>
        {% for k,row in user_dict.items %}
            <li><a  target="_blank"  href="/CC/detail-{{ k}}.html">{{ row.name }}</a></li>
        {% endfor %}
    </ul>

    <ul>
        {% for k in user_dict.keys %}
            <li>{{ k }}-</li>
        {% endfor %}
    </ul>
    <ul>
        {% for row in user_dict.values %}
            <li>-{{ row }}</li>
        {% endfor %}
    </ul>

  后台代码:

USER_DICT={
    "1":{"name":"root1","email":"123"},
    "2":{"name":"root2","email":"123"},
    "3":{"name":"root3","email":"123"},
    "4":{"name":"root4","email":"123"},
}
def index(request):
    return  render(request,"index1.html",{‘user_dict‘:USER_DICT})

  

def detail(request):
    print ‘2222222222222‘,request.GET
    nid =request.GET.get("nid")
    detail_info = USER_DICT[nid]
    return render(request,‘detail.html‘,{"dict":detail_info})

  detail.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
        <h3>详细信息</h3>
        <p> name :{{ dict.name }}</p>
        <p> email :{{ dict.email }}</p>


</body>
</html>

  

  

 

前端循环字典的方式

标签:val   har   index   blank   html   ret   turn   charset   信息   

原文地址:https://www.cnblogs.com/qiangayz/p/8971373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!