template.html
views.py
<!DOCTYPE html>
<html>
<body>
{% for x in cars|dictsort:"year" %}
<p>{{ x.year }} {{ x.brand }} {{ x.model }}.</p>
{% endfor %}
<p>In views.py you can see what the colors variable looks like.</p>
</body>
</html>
from django.http import HttpResponse
from django.template import loader
def testing(request):
template = loader.get_template('template.html')
context = {
'cars': [
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964},
{'brand': 'Volvo', 'model': 'XC90', 'year': 2022},
{'brand': 'Volvo', 'model': 'P1800', 'year': 1962},
{'brand': 'Ford', 'model': 'Focus', 'year': 2004},
]
}
return HttpResponse(template.render(context, request))