0
ユーザーが数字を入力し、その数字のピタゴラスのトリプルを計算するアプリケーションを作成しました。ジンジャーテンプレートのリストのpythonリストを表示
トリプルをリストに入れてHTMLテーブルに表示する際に問題があります。 サーバーサイド方式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pythagorean Triples</title>
</head>
<body>
<table>
<th>A</th>
<th>B</th>
<th>C</th>
{% for triple in allTriples %}
<p>triple</p>
<tr>
{% for val in triple %}
<td>val</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</body>
</html>
HTMLは言葉だけ "ヴァル" を示しています。15は
[[3, 4, 5], [5, 12, 13], [6, 8, 10]]
神社テンプレートに入力されたときに
def post(self):
allTriples = []
c = int(self.request.get('c'))
print('c: ' + str(c))
for i in range(1, c):
for j in range(1, c):
for k in range(1, c):
i2 = i*i
j2 = j*j
k2 = k*k
if ((i2 + j2) == k2) and (i < j):
singleTriple = []
singleTriple.append(i)
singleTriple.append(j)
singleTriple.append(k)
allTriples.append(singleTriple)
d = {
'allTriples' : allTriples,
}
print(allTriples)
template = JINJA_ENVIRONMENT.get_template('triples.html')
self.response.out.write(template.render(d))
はここでリストのリストの出力です数字はどこにあるべきですか?
を使用する必要があり、あなたのテンプレートコードで をタイプミス。 –
と同様に '
トリプル
'を '{{triple}}
'に置き換えてください(これはデバッグ用のものです) –