- 注册时间
- 2012-7-19
- 最后登录
- 2021-10-26
- 阅读权限
- 10
- 积分
- 319
- 精华
- 0
- 帖子
- 64
|
MYSQL分页处理
from flask import Flask,request,render_template
from flask import jsonify
import pymysql
app = Flask(__name__)
def createdb():
conn=pymysql.connect("127.0.0.1","root","","test")
cursor=conn.cursor()
return cursor
@app.route('/name')
def hello_world():
return render_template('datagrid.html')
@app.route('/name/index',methods=['GET', 'POST'])
def hello():
my=createdb()
a=[]
index=request.form.get("pageIndex")
size=request.form.get("pageSize")
start = int(index) * int(size)
key=request.form.get("key")
if key==None:
key=''
#print(key)
my.execute("select * from age where xm like '%"+key+"%' limit "+str(start)+","+size)
cur1=my.fetchall()
for cur in cur1:
aa={'xm':cur[0],'age':cur[1],'class':cur[2]}
a.append(aa)
my.execute("select count(*) from age where xm like '%" + key + "%'")
count1 = my.fetchall()
#a.append(cur1)
#aa=[]
#aa1=jsonify(a)
aa2={'total':count1[0],'data':a}
#print(cur1)
return jsonify(aa2)
if __name__ == '__main__':
app.run(debug(true))
|
|