Answers for "django template render dictionary"

0

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 %}
Posted by: Guest on October-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language