python:如何将下拉选择值存储到python变量

时间:2015-07-24 09:49:29

标签: python html-select

我使用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中有任何选项..?

请帮助我......

0 个答案:

没有答案