私のWebページは現在表示されていません。他のサンプルを見ていますが、私は値に正しくアクセスしていますが、データを取得していないようです。 djangoテンプレート内のリストから値にアクセスする
生成されたテンプレート
{% 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>
に無関係なを持っていません質問は、あなたのコードを少し作るだろうもしあなたがあなたのUserコンストラクタにobjOnCallを渡すことができるなら、クリーナー。 – SpoonMeiser
@alecxeは基本テンプレートを追加しました – AlexW
@alecxeあなたは何を意味するのでしょうか? iveは、コードが生成されるという質問にhtmlを追加しました。テンプレートは動作していますが、データを取得していないようです。 – AlexW