Flask怎么做分页功能呀,本人最近在用Flask做接口但是分页不会搞,一页就展示几万条数据,加载太慢了 各位大佬们支个招看看加在哪里比较合适,感谢感谢!!
from flask import Flask, render_template
import pymysql
app = Flask(__name__)
@app.route('/')
def index():
conn = pymysql.connect('localhost', 'root', '????', database='????', charset='utf8')
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
sql = '''
SELECT * FROM meituan_data
'''
res = cursor.execute(sql)
conn.commit()
u = cursor.fetchall()
return render_template('c.html', u=u)
if __name__ == '__main__':
app.debug = True
app.run(port=8003)
HTML代码部分
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
/*表格样式*/
table {
width: 90%;
background: #ccc;
margin: 10px auto;
border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
}
th,td {
height: 25px;
line-height: 25px;
text-align: center;
border: 1px solid #ccc;
}
th {
background: #eee;
font-weight: normal;
}
tr {
background: #fff;
}
tr:hover {
background: #cc0;
}
td a {
color: #06f;
text-decoration: none;
}
td a:hover {
color: #06f;
text-decoration: underline;
}
</style>
</head>
<body>
<table>
<tr>
<th>序号</th>
<th>店铺</th>
<th>关键词</th>
<th>手机号</th>
<th>地址</th>
</tr>
{% for i in u %}
<tr>
<td>{{ i['id'] }}</td>
<td>{{ i['shop'] }}</td>
<td>{{ i['key_word'] }}</td>
<td>{{ i['phone'] }}</td>
<td>{{ i['address'] }}</td>
</tr>
{% endfor %}
</table>
</body>