django - 来自views.py的值,没有反映在HTML页面中:Django
问题描述
我在将元素从 views.py 传递到 html 页面时遇到问题,首先我将解释 UI,我有一个带有名称的 html 页面。
side-menu-light-tabulator.html
当我点击显示服务器列表时,它将显示 div 并向我显示另一个 div,其中另一个表替换旧表,因为您可以看到“文档编辑器”在仅标题表更改中保持不变。
将第一个 UI 视为表 1,将第二个 UI 视为表 2,因此我通过对表 1 数据执行一些查询来获取表 2 的数据,表 1 工作正常,并且在使用从表 1 获得的数据执行查询时也打印在终端,但是当我通过返回渲染发送数据时,它没有打印在表 2 中。
所以这是我的代码:
def secondtableonDashboard(request):
Server_list = ""
NewList = ""
afterConcat = ""
conn = pyodbc.connect('Driver={SQL Server};'
'Server=ABC\SQLEXPRESS;'
'Database=WebstartUI;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.execute("select * from CustomerServer")
result = cursor.fetchall()
if request.method=='POST': # ------> getting value from first table
user_list = request.POST.getlist('checked_list')
Server_list = listToString(user_list) +","
else:
print("No Values")
for listValue in Server_list.split(","):
NewList = "'"+listValue+"',"
afterConcat = afterConcat + NewList
Server_list = afterConcat[:-5]
Server_list = Server_list[1:]
ServiceList = conn.cursor()
cmd = "Select * from dbo.ServiceRunningStatus where ServerName IN ('"+Server_list+"')" #---> performing query
ServiceList.execute(cmd)
resultOfServiceList = ServiceList.fetchall()
print(resultOfServiceList) #---> result gets printed perfectly .
return render(request,'side-menu-light-tabulator.html',{'customerserver':result,'ServerList':resultOfServiceList}) #-->
返回结果...这里 customerserver 是第一个表数据,ServerList 是第二个表数据
html:
{% for services in ServerList %}
<td>{{services.ServerName}}</td>
<td>{{services.Component}}</td>
<td>{{services.PID}}</td>
<td>{{services.State}}</td>
{% endfor %}
但此数据未打印在第二张表上,也未打印在网络响应预览中。谁能帮我找出我做的错误
解决方案
推荐阅读
- azure - Azure 容器经常连接到 23.97.221.176:11041。这个端口是干什么用的?
- python - 将 2 个列表与元组、列表和整数合并
- c# - 如何在列表视图中的文件资源管理器中区分 FileInfo 和 DirectoryInfo
- entity-framework - 当在 CRUD 中创建时显示其他列然后是外键
- python - 预期 LP_c_ubyte 实例而不是 str?
- css - 如何将不同大小的倾斜文本正确定位到特定区域?
- javascript - JavaScript 代码的概念性问题。请解释我得到的输出
- python - Python 中的 KeyConditions 和 KeyConditionExpression 失败
- google-chrome-extension - 使用 webRequest API 拦截脚本请求,编辑并发送回
- android - PreferenceFragmentCompat 影响其他片段的性能