我正在与Flask一起构建一个从SQLAlchemy数据库中获取的人员列表中的Bootstrap表。但是,我想要放在表格中的信息出现在它上面。
以下是相关代码:
<!DOCTYPE html>
{% extends "base.html" %}
{% block page_content %}
<div class="page-header">
<h1>componentes familiares</h1>
<table class="table">
<thead>
<th>name</th>
<th>age</th>
<th>option</th>
</thead>
<tbody>
{% for person in people %}
<tr>{{ person.name }}</tr>
<tr>{{ person.age }}</tr>
<tr>{{ person.option }}</tr>
{% endblock %}
</tbody>
</table>
{% endblock %}
(这已经是一个精简版,因为我一直在拿东西看它是否能解决这个问题。)
但是,假设我的数据库中有两个人,Alice和Bob。爱丽丝30岁,鲍勃40岁,爱丽丝选择1,鲍勃2岁。这就是我得到的:
信息在那里,但它在表格上方呈现。在它下面是表头和一个空表行。
链接
我在Flask here中发现了另一个关于Bootstrap表的问题,但它并没有真正解决我的问题。我的数据完全按照我的要求传递到html页面,我只是想把它放在一个表格中。
我还找到了Flask-Table,这是在Python中构建表然后使用它的扩展。它可能最终成为一种解决方案,但我仍然没有看到我的代码出了什么问题。
在Bootstrap docs中找不到任何有用的内容。
任何帮助都非常感谢!
答案 0 :(得分:11)
您错过了一些a
和<tr>
代码:
<td>
您的目标是每个用户的表格行(<table class="table">
<thead>
<tr>
<th>name</th>
<th>age</th>
<th>option</th>
<tr>
</thead>
<tbody>
{% for person in people %}
<tr>
<td>{{ person.name }}</td>
<td>{{ person.age }}</td>
<td>{{ person.option }}</td>
</tr>
{% endfor %}
</tbody>
</table>
),以及每个属性的一些表格数据(<tr>
)。您还有一个<td>
,您应该拥有{% endblock %}
。