<s:debug/>

<s:debug/>
请给如下每行代码添加注释:# -*- coding: utf-8 -*- from flask import Flask, request import sqlite3 app = Flask(__name__) # 连接 SQLite 数据库 conn = sqlite3.connect('entable.db') cursor = conn.cursor() @app.route('/') def index(): return ''' <html> <head> <title>搜索框</title> <style type="text/css"> #search-box { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); border: 1px solid #ccc; border-radius: 20px; background-image: url('search-icon.png'); background-repeat: no-repeat; background-position: 10px center; padding: 10px 20px 10px 45px; font-size: 16px; } #search-box input[type="text"] { border: none; outline: none; width: 100%; padding: 5px 10px; } #search-box input[type="submit"] { border: none; outline: none; background-color: transparent; font-size: 16px; color: #666; cursor: pointer; margin-left: 15px; } #search-result { position: absolute; top: 100px; left: 0; width: 100%; text-align: center; font-size: 20px; } </style> </head> <body> <form id="search-box" method="get" action="/search"> <input type="text" name="q" placeholder="请输入要查询的字符串" /> <input type="submit" value="查询" /> </form> </body> </html> ''' @app.route('/search') def search(): query = request.args.get('q') cursor.execute("SELECT * FROM core WHERE EN LIKE ?", ['%' + query + '%']) results = cursor.fetchall() if not results: return '<h3 id="search-result">您查询的内容暂时没有收录</h3>' else: return ''' <html> <head> <title>搜索结果</title> <style type="text/css"> #search-result { position: absolute; top: 100px; left: 0; width: 100%; text-align: center; font-size: 20px; } </style> </head> <body> <h3 id="search-result">查询结果:</h3> <ul> %s </ul> </body> </html> ''' % ''.join(['<li>%s %s %s %s</li>' % r for r in results]) if __name__ == '__main__': app.run(debug=True)
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值