Djangoテンプレート内から配列の要素にアクセスしようとしていますが、 "フィールドが見つかりません"というエラーが表示されています。次のように私のテンプレートの構文は次のとおりです。私のスタックを読むDjangoテンプレート内の配列要素にアクセス - ユニコード参照のため "フィールドが見つかりません"エラー
<h3>Data:</h3>
<table>
<thead>
<tr><th> Row[0] </th><th> Row[1] </th><th> Row[2] </th></tr>
</thead>
<tbody>
{% for row in info %}
<tr>
<td>{{ row.0 }}</td>
<td align = 'center'>{{ row.1 }}</td>
<td align = 'center'>{{ row.2 }}</td>
</tr>
{% endfor %}
</tbody>
</table>
問題は、テンプレートエンジンは添字のユニコードバージョンを使用して、配列のフィールドを参照しようとしていることであるように見えトレース。その結果:
{{ row.0 }}
をrow[u'0']
なく
row[0]
それによってエラーの原因として参照されます。
正確なエラーは次のとおりです。だから、それはリストのインデックス検索をしようとするポイントになっていません
current = context
try: # catch-all for silent variable failures
for bit in self.lookups:
try: # dictionary lookup
==> current = current[bit]
except (TypeError, AttributeError, KeyError):
try: # attribute lookup
current = getattr(current, bit)
except (TypeError, AttributeError):
try: # list-index lookup
current = current[int(bit)]
:それは時に発生しているCaught ValueError while rendering: field named 0 not found
。これはなぜでしょうか?
{% for row in info %}
<tr>
{% for value in row %}
<td {% if forloop.counter > 0 %}align = 'center'{% endif %}> {{ value }} </td>
{% endfor %}
</tr>
{% endfor %}
私の答えが役に立たない場合は、infoのリストを提供してください。 –