简体   繁体   English

如何在 html django 页面中显示我的 sqlite 查询的结果

[英]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}} &nbsp {{i.OriginatorDNHANDELED (use the names you use in the 
            Model)}} </li>
    {% endfor %}
 {% endfor %}
   </ul>
 {% endblock %}`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 html 显示我的 django model? - How can I get my html to display my django model? 如何使用 Django 在 Python 中查看我的 HTML 页面 - How can I view my HTML page in Python using Django 如何将结果从 SQLite db 显示到 html? - How to display the result from SQLite db to html? 如何从 Django 中的 views.py 获取变量并将其显示在我的 HTML 页面上 - How do I take a variable from views.py in Django and display it on my HTML page 使用Python,flask和SQLAlchemy如何将数据库查询的结果打印在HTML页面上? - Using Python, flask and SQLAlchemy How can I print on an HTML page the result of a DB query? 我如何制作一个页面,该页面将始终显示Django模型中的最新帖子 - How can I make a page that will always display the latest post from my Django Model 如何在帖子详细信息页面 Django 上显示我的评论表单 - How can I display my comment form on the post detail page Django 如何要求用户将图像上传到 html 页面,使用 flask 将此图像插入到 sqlite3 表中,然后使用 jinja 显示此图像? - How can I ask user to upload image to an html page, insert this image to an sqlite3 table using flask, and then display this image using jinja? 如何在新页面中显示 django 搜索结果 - how to display django search result in new page PySimpleGUI:如何在我的 window 中显示结果? - PySimpleGUI: How can I display a result in my window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM