媒体大数据词汇表查询(Python+Flask+MySQL)

媒体大数据词汇表查询(Python+Flask+MySQL),第1张

概述Python+Flask+MySQL词汇表查询MySQL导入词汇表代码实现Python的Flask应用HTML前端代码运行结果MySQL导入词汇表代码实现Python的Flask应用importpymysqlfromflaskimportFlask,render_template,requestapp=Flask(__name__)@app.route('/')defenglish():

Python+Flask+MysqL词汇表查询MySQL导入词汇表代码实现Python的Flask应用HTML前端代码运行结果

MysqL导入词汇表

代码实现Python的Flask应用
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)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1184955.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存