weixin_45437935 2020-10-21 16:51 采纳率: 0%
浏览 70

Flask怎么做分页功能呀,各位大佬们!

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>
  • 写回答

1条回答 默认 最新

  • PythonJavaC++go 2020-10-21 19:07
    关注

    方法一:sql写成翻页查询返回

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料