iterate dict value in django template code example

Example 1: iterate over dictionary django

{% for key, value in data.items %}
    <tr>
        <td> Key: {{ key }} </td> 
        <td> Value: {{ value }} </td>
    </tr>
{% endfor %}

Example 2: django template render dictionary

#In views.py (Python2):

return render_to_response('results.html',
    {'data': sorted(results_dict.iteritems())})
#Or in views.py (Python3):

return render_to_response('results.html',
    {'data': sorted(results_dict.items())})
#In template file:

{% for key, value in data.items() %}
    <tr>
        <td> {{ key }}: </td> <td> {{ value }} </td>
    </tr>
{% endfor %}