Reputation: 509
I am unable to show data from the database to HTML. I am getting ordered dict from the serializer.
views.py
material_class = Material.objects.filter(material_class=user_class.user_class)
data = MaterialSerializer(material_class, many=True)
content = {'material':data.data}
# In *data.data* I am getting this [OrderedDict([('id', '123'),('material','456')]),
OrderedDict([('id','345'),('material','789')])]
return render(request, 'dashboard/dashboard.html',content)
dashboard.html
{% load static %}
{% csrf_token %}
<!DOCTYPE html>
<html lang="en">
<head>
{% block content %}
{% for a in content %}
<p>{{ a }}</p>
{% endfor %}
{% endblock %}
</head>
</html>
Upvotes: 1
Views: 34
Reputation: 5200
Try this in last line of your view.
return render(request, 'dashboard/dashboard.html', {'content': content})
You have to pass a dictionary of values and their keys. You were passing just the OrderedDict.
Upvotes: 2