jQuery MiniUI

标题: python flask调用miniui框架,仅供参考 [打印本页]

作者: fsgameboy    时间: 2020-3-28 11:51:12     标题: python flask调用miniui框架,仅供参考

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))

作者: fsgameboy    时间: 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))





欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2