我使用python2.7
,我想将选定的dropdown
值存储到python
变量。我使用以下代码填充了database
值的下拉列表:
import MySQLdb
def db_dropdown():
db = MySQLdb.connect(user='root', db='test', passwd='test', host='ip-address')
cursor = db.cursor()
sql = 'SELECT username FROM emplist'
cursor.execute(sql)
list_tested = cursor.fetchall()
list_tested = [i for sub in list_tested for i in sub]
return list_tested
print "content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '</head>'
print '<body>'
def print_dropdown(data):
print '<div>'
print '<select>'
for i in data:
print '<option value="%s">%s</option>' % (i, i)
print '</select>'
print '</div>'
print_dropdown(db_dropdown())
print '</body>'
print '</html>'
使用此代码,我的dropdown
填充了数据库值。现在我想将选定的dropdown
值存储到python
变量。这该怎么做..? python中有任何选项..?