Generate a dynamic table with javascript in Dango
- Configuration:
- Dango 2.0
- Python 3.6.5
- Javacript
my/bs/urls.py
from django.shortcuts import render
from django.conf.urls import url
from . import views
urlpatterns = [
**url(r'^bs5$', views.bs_bs5, name="bootstrap_bs5"),**
]
my/bs/urls.py
def bs_bs5(request):
tests1 ={'number':'111','name':'hans','labs':'Tsinghua'}
tests2 ={'a':{'number':'121','name':'hans','labs':'Tsinghua'},
'b':{'number':'123','name':'amy','labs':'Peking'}}
print(tests1)
print(tests2)
return render(request, 'bs5.html', {'tests2': tests2} )
my/static/html/bs5.html
<body>
<table class="table table-hover">
<caption>Table hello</caption>
<thead>
<tr>
<th>Number</th>
<th>Standard</th>
<th>Labs</th>
</tr>
</thead>
<tbody>
{% for k,v in tests2.items%}
<tr>
{% for k1,v1 in v.items%}
<td>{{ v1 }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</body>
Result in the web: