前端循環字典的方式


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>

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM