django template question (accessing a list)

前端 未结 4 1531
半阙折子戏
半阙折子戏 2021-01-07 04:14

I am writing a template for my first django website.

I am passing a list of dictionaries to the template in a variable. I also need to pass a few other lists which h

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-07 04:45

    You use the dot-operator to index the array, or, really, to do anything.

    Technically, when the template system encounters a dot, it tries the following lookups, in this order:

    * Dictionary lookup
    * Attribute lookup
    * Method call
    * List-index lookup
    

    I don't believe you can do math on the index. You'll have to pass in your array constructed in some other way so that you don't have to do this subtraction.

提交回复
热议问题