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

后端 未结 5 940
梦毁少年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:18

    If you have a fixed number in your tuples, you could just use indexing. I needed to mix a dictionary and the values were tuples, so I did this:

    In the view:

    my_dict = {'parrot': ('dead', 'stone'), 'lumberjack': ('sleep_all_night', 'work_all_day')}
    

    In the template:

    
    

提交回复
热议问题