所以我对django和模板有点陌生,我不知道该怎么做。我有一个文件叫做服务.py在我的项目结构中,我有几个函数执行身份验证、调用api、返回数据、解析数据并将其输入到多个字典中。api是这样的:
{
CheckName: "AppPools",
Description: "DefaultAppPool",
GroupName: "Server1",
Links: [
{
description: "Recycles the DefaultAppPool app pool.",
link: "Recyle/Server1/DefaultAppPool",
title: "Recycle"
},
{
description: "Stops the DefaultAppPool app pool.",
link: "Stop/Server1/DefaultAppPool",
title: "Stop"
},
{
description: "Starts the DefaultAppPool app pool.",
link: "Start/Server1/DefaultAppPool",
title: "Start"
}
]
},
{
CheckName: "AppPools",
Description: "FinancialServices",
GroupName: "ST0PWEB12",
Links: [
{
description: "Recycles the FinancialServices app pool.",
link: "Recyle/Server2/FinancialServices",
title: "Recycle"
},
{
description: "Stops the FinancialServices app pool.",
link: "Stop/Server2/FinancialServices",
title: "Stop"
},
{
description: "Starts the FinancialServices app pool.",
link: "Start/Server2/FinancialServices",
title: "Start"
}
]
},
这里有等级制度
^{pr2}$我用以下格式将数据存储在词典中
名为groupsInChecks的函数使用以下格式创建dict:
{CheckName1:(GroupName1,GroupName2, GroupName3), CheckName2:(GroupName4,Grouonam5, GroupName6)}
函数serviesInGroups使用以下格式创建dict:
{Groupname1:(Description1, Description2, Description3), GroupName2:(Description5. Description6, Description7)}
然后返回dict,这些dicts嵌套为值。在
我有我的看法视图.py公司名称:
def app_status(request):
data=ntlmAuthGetRequest() #does api request gets json data
groups=groupsInChecks(data) #parses into first dict
services=serviesInGroups(data) #parses into second dict
return render(request, 'application_status/app_status_page.html') #this is where im lost how do i pass this to the html file
另外,在html文件中,我需要用这些数据动态地创建一个表,也不知道如何去做。在
任何小费都会很好。另外,如何导入我的服务.py用我的观点。在
谢谢!在
不管你有多少个dict或其他值。无论数字是什么,它们都会在第三个参数中传递给
render
,这本身就是一个dict将多个变量传递到django模板
在你的视图.py文件您必须导入服务.py文件以使用它提供的功能
在html模板文件中,可以通过
^{pr2}$相关问题 更多 >
编程相关推荐