Python 从SQLITE到Flask页面中HTML表的数据
我在SQLite3中有一个表,我需要获取表中几乎所有的列,并将它们输出到网页。对于其他页面,我使用了flask,但这始终是将3或4个单值变量传递到模板中的情况Python 从SQLITE到Flask页面中HTML表的数据,python,sqlite,flask,Python,Sqlite,Flask,我在SQLite3中有一个表,我需要获取表中几乎所有的列,并将它们输出到网页。对于其他页面,我使用了flask,但这始终是将3或4个单值变量传递到模板中的情况 我猜这是一种类似于将光标或更可能是来自光标.fetchall()调用的行传递到模板中,然后在模板中为行中的行循环传递数据的方式?将数据作为某种集合传递,无论是类似于中的字典还是更简单的元组或列表 是的,在模板中,您将使用{%for集合%}->{%endfor%}循环来呈现数据库中的所有数据 Python方法示例: @app.route('
我猜这是一种类似于将光标或更可能是来自
光标.fetchall()
调用的行传递到模板中,然后在模板中为行中的行循环传递数据的方式?将数据作为某种集合传递,无论是类似于中的字典还是更简单的元组或列表
是的,在模板中,您将使用{%for集合%}->{%endfor%}
循环来呈现数据库中的所有数据
Python方法示例:
@app.route('/print_items')
def print_items():
cursor = db.execute('SELECT column1,column2,column3,column4 FROM tablename')
return render_template('print_items.html', items=cursor.fetchall())
模板部分示例:
<table>
{% for item in items %}
<tr>
<td>column1</td>
<td>column2</td>
<td>column3</td>
<td>column4</td>
</td>
{% endfor %}
{items%%中的项的%s}
专栏1
专栏2
第3栏
专栏4
{%endfor%}
将数据作为某种集合传递,无论是类似于中的字典,还是更简单的元组或列表
是的,在模板中,您将使用{%for集合%}->{%endfor%}
循环来呈现数据库中的所有数据
Python方法示例:
@app.route('/print_items')
def print_items():
cursor = db.execute('SELECT column1,column2,column3,column4 FROM tablename')
return render_template('print_items.html', items=cursor.fetchall())
模板部分示例:
<table>
{% for item in items %}
<tr>
<td>column1</td>
<td>column2</td>
<td>column3</td>
<td>column4</td>
</td>
{% endfor %}
{items%%中的项的%s}
专栏1
专栏2
第3栏
专栏4
{%endfor%}
将数据作为某种集合传递,无论是类似于中的字典,还是更简单的元组或列表
是的,在模板中,您将使用{%for集合%}->{%endfor%}
循环来呈现数据库中的所有数据
Python方法示例:
@app.route('/print_items')
def print_items():
cursor = db.execute('SELECT column1,column2,column3,column4 FROM tablename')
return render_template('print_items.html', items=cursor.fetchall())
模板部分示例:
<table>
{% for item in items %}
<tr>
<td>column1</td>
<td>column2</td>
<td>column3</td>
<td>column4</td>
</td>
{% endfor %}
{items%%中的项的%s}
专栏1
专栏2
第3栏
专栏4
{%endfor%}
将数据作为某种集合传递,无论是类似于中的字典,还是更简单的元组或列表
是的,在模板中,您将使用{%for集合%}->{%endfor%}
循环来呈现数据库中的所有数据
Python方法示例:
@app.route('/print_items')
def print_items():
cursor = db.execute('SELECT column1,column2,column3,column4 FROM tablename')
return render_template('print_items.html', items=cursor.fetchall())
模板部分示例:
<table>
{% for item in items %}
<tr>
<td>column1</td>
<td>column2</td>
<td>column3</td>
<td>column4</td>
</td>
{% endfor %}
{items%%中的项的%s}
专栏1
专栏2
第3栏
专栏4
{%endfor%}
它应该是:
<table>
{% for item in items %}
<tr>
<td>{{column1}}</td>
<td>{{column2}}</td>
<td>{{column3}}</td>
<td>{{column4}}</td>
</tr>
{% endfor %}
</table>
{items%%中的项的%s}
{{column1}}
{{column2}}
{{column3}}
{{column4}}
{%endfor%}
它应该是:
<table>
{% for item in items %}
<tr>
<td>{{column1}}</td>
<td>{{column2}}</td>
<td>{{column3}}</td>
<td>{{column4}}</td>
</tr>
{% endfor %}
</table>
{items%%中的项的%s}
{{column1}}
{{column2}}
{{column3}}
{{column4}}
{%endfor%}
它应该是:
<table>
{% for item in items %}
<tr>
<td>{{column1}}</td>
<td>{{column2}}</td>
<td>{{column3}}</td>
<td>{{column4}}</td>
</tr>
{% endfor %}
</table>
{items%%中的项的%s}
{{column1}}
{{column2}}
{{column3}}
{{column4}}
{%endfor%}
它应该是:
<table>
{% for item in items %}
<tr>
<td>{{column1}}</td>
<td>{{column2}}</td>
<td>{{column3}}</td>
<td>{{column4}}</td>
</tr>
{% endfor %}
</table>
{items%%中的项的%s}
{{column1}}
{{column2}}
{{column3}}
{{column4}}
{%endfor%}
您需要遵循以下步骤:
[HTML]:
<table>
{% for item in items %}
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
</td>
{% endfor %}
您需要遵循以下步骤: [HTML]:
<table>
{% for item in items %}
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
</td>
{% endfor %}
您需要遵循以下步骤: [HTML]:
<table>
{% for item in items %}
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
</td>
{% endfor %}
您需要遵循以下步骤: [HTML]:
<table>
{% for item in items %}
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
</td>
{% endfor %}
这里有一个例子,你看过烧瓶教程了吗?这里有一个例子,你看过烧瓶教程了吗?这里有一个例子,你看过烧瓶教程了吗?这里有一个例子,你看过烧瓶教程了吗?有一个问题。