[Fixed]-Filter in template to arrange data specifically in django

1👍

Alright then here we go. This is how you loop over a dictionary in an html page using Django:

<tbody> 
    <tr> 
    {% for desc in dim_description.all %} 
        <th> {{ desc }}</th>  
    {% endfor %} 
    </tr>
    {% for key, values in reading_desc.items %} 
    <tr>
        <td class="some_class_here"> {{ key }} </td> 
        {% for v in values %}
        <td class="some_class_here">{{ v }}</td>
        {% endfor %}
    <tr>
    {% endfor %}                 
</tbody> 

This should be enough to get you going. There’s a few things happening here. First, in the first loop that iterates over the dim_description list, we are adding a single row with a number of <th> tags to display the headers (in your case 1-24). Then in the second loop we are looping over the dictionary. We start with displaying the key (Inner OD for the first iteration), then we have to loop over all the values for each key (the inner for loop in the second for loop in the page) and it should display what you want. This may not be the full answer but it should give you the bones enough to tackle your problem.

Leave a comment