媒体大数据词汇表查询(Python+Flask+MySQL)
2021/6/10 2:22:48
本文主要是介绍媒体大数据词汇表查询(Python+Flask+MySQL),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python+Flask+MySQL词汇表查询
- MySQL导入词汇表
- 代码实现Python的Flask应用
- HTML前端代码
- 运行结果
MySQL导入词汇表
代码实现Python的Flask应用
import pymysql from flask import Flask,render_template,request app=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)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-20部署MySQL集群入门:新手必读指南
- 2024-11-20部署MySQL集群教程:初学者指南
- 2024-11-20部署MySQL集群项目实战:新手教程
- 2024-11-20部署MySQL集群资料:新手入门教程
- 2024-11-20MySQL集群部署教程:入门级详解
- 2024-11-20MySQL集群教程:入门与实践指南
- 2024-11-20部署MySQL集群教程:新手入门指南
- 2024-11-20MySQL读写分离教程:轻松入门
- 2024-11-20部署MySQL集群入门:一步一步搭建你的数据库集群
- 2024-11-19部署MySQL集群学习:入门教程