jQuery MiniUI

 找回密码
 立即注册
查看: 4020|回复: 1
打印 上一主题 下一主题

python flask调用miniui框架,仅供参考 [复制链接]

Rank: 3Rank: 3

跳转到指定楼层
楼主
发表于 2020-3-28 11:51:12 |只看该作者 |倒序浏览
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=[]
    page=request.form.get("pageIndex")
    size=request.form.get("pageSize")
    key=request.form.get("key")
    my.execute("select * from age where xm like'%"+key+"%'")
    cur1=my.fetchall()
    for cur in cur1:
        aa={'xm':cur[0],'age':cur[1],'class':cur[2]}
        a.append(aa)
    return jsonify(a)


if __name__ == '__main__':

    app.run(debug(true))

Rank: 3Rank: 3

沙发
发表于 2020-3-29 01:23:31 |只看该作者
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))

Archiver|普加软件

GMT+8, 2024-11-27 06:39 , Processed in 1.050411 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部