我对python相对较新,我的头衔几乎都说明了。我在这里查看,我能找到的最接近的是用PHP而不是python。
我编写的代码是在点击搜索按钮的情况下执行搜索,在我的数据库中搜索在提供的空白处键入的关键字,并在我的网页上显示该关键字中包含该关键字的所有相应网址。
现在我需要下拉菜单填充加载包含所有关键字的页面,并且能够点击关键字将执行搜索,就像键入关键字一样。我的下拉列表将为k1-k13列提取,其中可能有也可能没有文本。我打算使用distinct来删除任何重复的单词和空白字段,但希望至少让它先工作。我确实有用XML编写的下拉列表。
这是我得到的:
#!/usr/bin/env python2.7
import sys
import sqlite3
from string import Template
from cgi import FieldStorage
from dateutil import parser
from textwrap import dedent
from eicpy.www import CGIHandler
from eicpy.sql import ezsql
from eicpy import www
from eicpy import cgierror
cgierror.enable(display=True)
DB = ezsql().connect("/usr/HTTPServer/dev7/data/asq1.db")
class Page(CGIHandler):
def handle1(self):
search_terms = self.fs.getfirst("searchinp", None)
if search_terms:
fields = search_terms.split(" ")
steps = []
apps = []
for field in fields:
recs = DB.execute("select issue, url, steps from help where k1='%s' or
k2='%s' or k3='%s' or k4='%s' or k5='%s' or k6='%s' or k7='%s' or
k8='%s' or k9='%s' or k10='%s' or k11='%s' or k12='%s' or k13='%s'" %
(field, field, field, field, field, field, field, field, field, field,
field, field, field)).fetchall()
#self.debug(recs)
for r in recs:
if r.steps == "S":
steps.append({
"issue" : r.issue,
"size" : "600x460",
"location" : "/" + r.url
})
if r.steps =="A":
apps.append({
"issue" : r.issue,
"size" : "600x460",
"location" : "/" + r.url
})
#self.debug(steps)
#self.debug(apps)
self.show({"steps": steps, "apps": apps})
else :
self.show({})
if __name__ == '__main__':
p = Page('Agent Support Query'
,'pt/asq.xml'
, ['/styles/asq.css'])
p.handle1()