I have the following JSON file
[{
"ID": 1,
"Name": "John Smith",
"IDNumber": "7606015012088"
},
{
"ID": 2,
"Name": "Molly Malone",
"IDNumber": "8606125033087"
}]
Which I want to display it in table format.I have parsed the json file using json.load(filename)
I have tried something like:
Views.py
import json
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.template.loader import render_to_string
# Create your views here.
with open('/home/kunal.jamdade/Desktop/PyCharmProjects/demo.json') as d:
data = json.load(d)
def load_json_table_format(request):
print(data)
html = render_to_string()
return HttpResponse({'d':data}, 'demoApp/demo.html', content_type="application/html")
#return JsonResponse(data, safe=False,content_type="application/html")
#return render(request, 'demoApp/demo.html', {'d': data}, content_type="application/html")
demo.html
<body>
{% if data %}
<table>
{% for k in d %}
{% for item_1, item_2 in k.items %}
<tr>
<td>{{ item_1 }}</td>
<td>{{ item_2 }}</td>
</tr>
{% endfor %}
{% endfor %}
</table>
{% endif %}
</body>
But it is not printing the anything?
{% if data %}to{% if d %}