Django - How to do tuple unpacking in a template 'for' loop

后端 未结 5 955
梦毁少年i
梦毁少年i 2020-12-13 05:57

In my views.py, I\'m building a list of two-tuples, where the second item in the tuple is another list, like this:

[ Product_Type_1, [ product_1, product_2 ]         


        
5条回答
  •  渐次进展
    2020-12-13 06:22

    You must used this way:

    {% for product_type, products in product_list.items %}
        print product_type
        {% for product in products %}
            print product
        {% endfor %}
    {% endfor %}
    

    Don't forget the variable items in the dictionary data

提交回复
热议问题