我查看的网页目前是空白的,查看其他样本,我似乎正在正确访问这些值,但我没有得到任何数据。 我已经通过打印来检查我的列表,并且它们都有大量的数据
模板
{% extends 'oncall/base.html' %}
{% block content %}
{% for pol in lstPolicy %}
<h2>1 - {{ pol.Name }}</h2>
{% for user in lstUsers %}
{% if user.Policy == pol.Name %}
<h3>2 -{{ user.Level }}</h3>
<p>
Mobile: {{ user.Mobile }}
From: {{ user.StartTime }} on {{ user.StartDate }}
Until: {{ user.EndTime }} on {{ user.EndDate }}
</p>
{% endif %}
{% endfor %}
{% endfor %}
{% endblock %}
基本模板
{% load staticfiles %}
<html>
<head>
<title>IT on call Rota</title>
</head>
<body>
<a href="/">Home</a>
{% block content %}
{% endblock %}
</body>
</html>
视图
# Create your views here.
def index(request):
lstPolicy = []
lstUsers = []
for objPolicy in objPolicyData['escalation_policies']:
strPolicyName = objPolicy['name']
if strPolicyName.lower().find('test') == -1:
classPolicy = Policy()
classPolicy.Name = strPolicyName
lstPolicy.append(strPolicyName)
for objOnCall in objPolicy['on_call']:
classUser = User()
classUser.Policy = strPolicyName
strLevel = ''
if objOnCall['level'] == 1:
strLevel == 'Primary on call'
elif objOnCall['level'] == 2:
strLevel == 'Backup on call'
elif objOnCall['level'] == 3:
strLevel == 'Tetiary on call'
classUser.Level = strLevel
classUser.StartDate = getDate(objOnCall['start'])
classUser.EndDate = getDate(objOnCall['end'])
classUser.StartTime = getTime(objOnCall['start'])
classUser.EndTime = getTime(objOnCall['end'])
objUser = objOnCall['user']
classUser.Name = objUser['name']
classUser.Mobile = getUserMobile(objUser['id'])
lstUsers.append(classUser)
return render(request, 'oncall/rota.html', {'lstUsers': lstUsers, 'lstPolicy': lstPolicy})
html生成
<html>
<head>
<title>IT on call Rota</title>
</head>
<body>
<a href="/">Home</a>
<h2>1 - </h2>
<h2>1 - </h2>
<h2>1 - </h2>
<h2>1 - </h2>
<h2>1 - </h2>
</body>
</html>
答案 0 :(得分:1)
您添加 strPolicyName :
f = FILTER e BY BagToString(condition) == 'clear' OR BagToString(condition) == 'partly cloudy';
但您必须添加 classPolicy :
lstPolicy.append(strPolicyName)
字符串没有名称属性:)