无法解包djang中的词典列表

2024-06-16 11:25:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我的物品清单如下:

this_json_reponse = ['{"queskey": 1, "ques": "test question 1", "ans": "test ans 1"}', '{"queskey": 2, "ques": "test question 2", "ans": "test ans 2"}', '{"queskey":
5, "ques": "bfxgrdytreyt4etgest4", "ans": "3353tet4"}', '{"queskey": 6, "ques": "tet4w64t", "ans": "f464etrtd"}', '{"queskey": 7, "ques": "fdszf3r3647", "ans": "gry5757"}']

我从另一个API调用收到这个消息。 我只需要列出所有的queskeyques现在:

1:试题1 2:试题2 ... 你知道吗

我尝试用嵌套循环解包,如下所示:

<ul>
    {% for this_item in this_json_reponse %}
    <li>{{ this_item }}</li>
        {% for a,b in this_item.items %}
            <li>{{ a }}</li>
        {% endfor %}
    {% endfor %}
</ul>

遗憾的是,经过长时间的打击/审判,我无法做到这一点。你知道吗

这是我的视图.py定义

    this_json_reponse=this_reponse.json()
    this_list=[]
    for item in this_json_reponse:
        this_list.append(item)
    return render (request,"listall.html",{"this_json_reponse": this_list})

Tags: intestjsonforlithisitemul