【发布时间】:2017-12-18 13:36:26
【问题描述】:
所以,我对 django 和模板有点陌生,我不知道该怎么做。我的项目结构中有一个名为 services.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"
}
]
},
这里有一个层次结构:
CheckName1
GroupName1
Description1
Description2
GroupName2
Description3
Description4
CheckName2
GroupName1
Description1
Description2
GroupName2
Description3
Description4
我已将数据存储在字典中,格式如下:
名为 groupsInChecks 的函数创建一个具有以下格式的字典:
{CheckName1:(GroupName1,GroupName2, GroupName3), CheckName2:(GroupName4,Grouonam5, GroupName6)}
名为 serviesInGroups 的函数创建一个具有以下格式的 dict:
{Groupname1:(Description1, Description2, Description3), GroupName2:(Description5. Description6, Description7)}
然后他们返回嵌套为值的字典。
我在 views.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 I'm lost, how do I pass this to the html file!
此外,在 html 文件中,我需要使用该数据动态创建一个表。我也不知道该怎么做。
欢迎任何提示。另外我如何将我的 services.py 导入到我的视图中以供使用。
【问题讨论】:
-
如果services.py文件在同一目录下,可以通过views.py文件中的
import service导入。
标签: python html django django-templates django-views