我得到一个arr传递给我的Django模板的数组.我要访问的阵列中的阵列的各个元素(例如arr[0],arr[1])等等,而不是通过整个阵列循环.
有没有办法在Django模板中做到这一点?
如何在django模板中使用变量作为索引?
现在我收到此错误:
Exception Type:
TemplateSyntaxError
Exception Value:
Could not parse the remainder: '[year]' from 'bikesProfit.[year]'
Run Code Online (Sandbox Code Playgroud)
我也尝试了,{{ bikesProfit.year }}但这给出了一个空洞的结果.
{% for year in years_list %}
<tr>
<th>Total profit {{ year }}:</th>
</tr>
<tr>
<th></th>
<th> {{ bikesProfit[year] }} </th>
...
Run Code Online (Sandbox Code Playgroud)