[英]How can I display the result of my sqlite query in a html django page
I have the following query set in my views.py
:我的
views.py
设置了以下查询:
with connection.cursor() as cursor:
#cursor.execute("SELECT AgentName FROM 'CSQ Agent Report' ")
cursor.execute("SELECT 'AgentName', count (*) FROM 'CSQ Agent Report' WHERE 'AgentName' != 'None' AND 'OriginatorDNHANDELED' = '1' or 'OriginatorDNNOTHANDELED' = '1' Group by 'AgentName'")
obj = cursor.fetchall()
context = {
'object': obj
}
return render(request,"CSQ/detail.html", context)
And I would like to display the result of the query in my html page:我想在我的 html 页面中显示查询的结果:
{% extends 'base.html' %}
{% block content %}
<h1> Stats Call Center Of Feb </h1>
<p> Nb of calls received by agent </p>
<ul>
{% for var in object %}
<li> {{var}} </li>
{% endfor %}
</ul>
{% endblock %}
I have the same query created in python and it works as expected :我在 python 中创建了相同的查询,它按预期工作:
cursor.execute(""" SELECT "AgentName", count (*) FROM "CSQ Agent Report" WHERE "AgentName" != "None" AND "OriginatorDNHANDELED" = '1' or "OriginatorDNNOTHANDELED" = '1' Group by "AgentName" """)
liste8= cursor.fetchall()
for i in range (len(liste8)):
print (liste8[i][0],liste8[i][1])
and the result in python is as follow : python中的结果如下:
Agent1 11
Agent2 41
Agent3 249
Agent4 46
Agent5 2
Agent6 216
Agent7 117
Agent8 242
Agent9 50
I would like to display the same resulat in my Html Django page as per python .我想按照 python 在我的 Html Django 页面中显示相同的结果。
Thanks谢谢
It looks like the query is returning nested arrays.看起来查询正在返回嵌套数组。 You can use the following code in order to get a similar output as the python console.
您可以使用以下代码来获得与 python 控制台类似的输出。 (The appearance might be different for which you will have to apply CSS but the pattern should be the same.)
(外观可能不同,您必须为其应用 CSS,但模式应该相同。)
`{% extends 'base.html' %}
{% block content %}
<h1> Stats Call Center Of Feb </h1>
<p> Nb of calls received by agent </p>
<ul>
{% for var in object %}
{% for i in var%}
<li> {{i.AgentName}}   {{i.OriginatorDNHANDELED (use the names you use in the
Model)}} </li>
{% endfor %}
{% endfor %}
</ul>
{% endblock %}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.