Python dictionary in to html table

后端 未结 7 1287
刺人心
刺人心 2020-12-23 21:33

Is there any way to print the python dictionary in to a table in HTML. I have a python dictionary and am sending to HTML by using

return render_template(\'i         


        
7条回答
  •  执念已碎
    2020-12-23 22:16

    I've had better luck putting the dictionary into a list of lists, then have the html loop through the list and print the table. The python would be:

    Table = []
    for key, value in results_dict.iteritems():    # or .items() in Python 3
        temp = []
        temp.extend([key,value])  #Note that this will change depending on the structure of your dictionary
        Table.append(temp)
    

    Then in your html you loop through the table.

    
    {% for t in table %}
        
        {% for i in t %}
            
        {% endfor %}
        
    {% endfor %}
     
    {{ i }}

提交回复
热议问题