相关疑难解决方法(0)

如何访问Django模板中的数组元素?

我得到一个arr传递给我的Django模板的数组.我要访问的阵列中的阵列的各个元素(例如arr[0],arr[1])等等,而不是通过整个阵列循环.

有没有办法在Django模板中做到这一点?

django

159
推荐指数
4
解决办法
12万
查看次数

如何在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)

python arrays django indexing templates

4
推荐指数
1
解决办法
6263
查看次数

标签 统计

django ×2

arrays ×1

indexing ×1

python ×1

templates ×1