django template question (accessing a list)

前端 未结 4 1536
半阙折子戏
半阙折子戏 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:23

    Perhaps a better way is to use forloop.last. Of course, this will require that you send to the template the specific level_one_flag and level_two_flag out of the level_one_flags and level_two_flags arrays, but I think this solution keeps a better logical separation between view and template:

    
        First page
        {% for item in data_tables %}
        
    {% if forloop.last and level_one_flag %}
    Premier League {% endif %}
    Junior league
    Member count {% if forloop.last and level_two_flag %}
    Ashtano League {% endif %}
    {% endfor %}

提交回复
热议问题