import pyMysqLfrom flask import Flask,render_template,requestapp=Flask(__name__)@app.route('/')def english(): db = pyMysqL.connect(host="127.0.0.1",user="root",password="Ppyh0615",database="engword",port=3306,charset="utf8") cursor = db.cursor() try: sql="select * from map_enword limit 200" cursor.execute(sql) rs = cursor.fetchall() rs = List(rs) print(rs) except: rs = 'db-error' print('py-db-error') db.close() return render_template('english.HTML', rs=rs)@app.route('/search')def search(): wanted = request.args.get("wanted", type=str) if wanted == None: wanted = 'pineapple' db = pyMysqL.connect(host="127.0.0.1",user="root",password="Ppyh0615",database="engword",port=3306,charset="utf8") cursor = db.cursor() try: sql = "select * from map_enword where english like '%" + wanted + "%'" cursor.execute(sql) rs = cursor.fetchall() rs = List(rs) print(rs) except: rs = 'db-error' print('py-db-error') db.close() return render_template('english.HTML',rs=rs)if __name__=='__main__': app.run()
HTML前端代码<!DOCTYPE HTML><HTML lang="en"><head> <Meta charset="UTF-8"> <Title>英语四六级词表</Title></head><body><h1>英语四六级词表</h1><form action="/search"> <input type="text" name="wanted" value="" default="apple"> <input type="submit" value="搜索"></form>{% for r in rs %}{{r}}<br>{% endfor %}</body></HTML>
运行结果 总结 以上是内存溢出为你收集整理的媒体大数据词汇表查询(Python+Flask+MySQL)全部内容,希望文章能够帮你解决媒体大数据词汇表查询(Python+Flask+MySQL)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)