def history(request):
itemsid = list()
agents = list()
dates = list()
source = list()
dynamodb_resource('dynamodb')
history_table = dynamodb_resource.Table('name_of_the_table')
all_items = history_table.scan()
for p in all_items['Items']:
itemsid.append((p['id'])),
agents.append((p['agent'])),
dates.append((p['date'])),
source.append((p['source']))
return render(request, 'history.html', {'itemsid':itemsid, 'agents':agents, 'dates':dates, 'source':source}
The issue is that I don't know how to write the html code to show a table with the rows: id, agent, date and source.
I have the following in history.html
<table>
{% for i in itemsid %}
<tr>
<td>{{ i }}</td>
...
but I don't know how to code it (how to loop it) to show the table with the lists as source.
Any idea please about how to parse a Json with the following format into a HTML with Django and Python please?.
JSON from DynamoDB:
{ 'Items: [ { 'id': '94f' 'agent': 'aws' 'date': '04/05 'source': 'case1' }, { 'id': 'lk42' ...
Thank you so much. I'm new in Django and in programming in general so any help is much appreciate.
View.py:
def history(request):
dynamodb_resource('dynamodb')
history_table = dynamodb_resource.Table('name_of_the_table')
all_items = history_table.scan()
return render(request, 'history.html', { items: all_items['Items'] })
Your template:
<table>
{% for item in items %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.agent }}</td>
<td>{{ item.date }}</td>
<td>{{ item.source }}</td>
</tr>
{% endfor %}
</table>