The way the front end loops the dictionary

index.html

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

  Background code:

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

  

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325122158&siteId=291194637