如何在html表中水平打印python列表(django)

时间:2020-04-14 10:44:38

标签: python html django

我有一个列表from IPython.display import Javascript Javascript('JupyterLab.notebook.execute_cells_below()') ,并且想要水平显示在html表中。我是html和django的新手。

Javascript Error: notebook is not defined

我做了下面的事情,但它垂直显示

l

这是我希望在可以显示年份的地方实现的目标:

l=[10,40,50]

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

您不应以<tr>结束<td>,即 row

<table>
    <tr><th>grades</th>
    {% for items in l %}
        <td>{{ items }}</td>
    {% endfor %}
    </tr>
</table>

如果您还通过了年份,也可以对它们进行排版,因此如果年份看起来像这样:

years = range(2019, 2016, -1)

我们可以渲染一个像这样的表:

<table>
    <tr><th></th>
    {% for year in years %}
        <th>{{ year }}</th>
    {% endfor %}
    </tr>
    <tr><th>grades</th>
    {% for items in l %}
        <td>{{ items }}</td>
    {% endfor %}
    </tr>
</table>