Jinja#
Generate HTML#
You can easily generate some html using jinja templates. For example, in the following cell I have displayed python dict as html using jinja templates.
from jinja2 import Template
from IPython.display import HTML
data = {'apple': 3, 'banana': 5, 'orange': 2}
template = Template('''
<table>
<thead>
<tr>
<th>Fruit</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
{% for key, value in data.items() %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
''')
html = template.render(data=data)
HTML(html)
Fruit | Quantity |
---|---|
apple | 3 |
banana | 5 |
orange | 2 |