首页 > 编程语言 > 详细

Python 多级目录选择

时间:2017-06-22 16:18:50      阅读:330      评论:0      收藏:0      [点我收藏+]

技术分享效果如图所示,可以根据条件来选择对象

 

cat pc.py 
#!/usr/bin/python
from flask import Flask,render_template,request,redirect,session
import MySQLdb as mysql

con = mysql.connect(host=‘59.110.**.**‘,user=‘woniu‘,passwd=‘123456‘,db=‘wangjin‘)
cur =con.cursor()
#sql = ‘select * from user where (username="%s") and (password="%s")‘%(‘tt‘,‘tt‘)
#cur.execute(sql)
#print  cur.fetchone()


app = Flask(__name__)
@app.route(‘/pc‘,methods=[‘GET‘,‘POST‘])
def pc():
    mem = request.args.get(‘mem‘)
    sql = ‘select * from pc‘
    cur.execute(sql)
    res = cur.fetchall()

    mem_list = []
    for item in res:
        m=item[1]
        if m not in mem_list:
            mem_list.append(m)
    
    pc_list = []
    for item in res:
        if not mem or (item[1]==int(mem)):
            pc_list.append(item)

    return render_template(‘pc.html‘,pc=pc_list,mem_list=sorted(mem_list))
if __name__=="__main__":
    app.run(host=‘0.0.0.0‘,port=12121,debug=True)

templates下的文件

cat pc.html 
<form>
<select name=‘mem‘>
    <option></option>
    {% for m in mem_list %}
    <option value="{{m}}">{{m}}G</option>
    {% endfor %}
</select>
<input type=‘submit‘ value=‘search‘>
</form>


<table border=‘1‘>
{% for p in pc %}
<tr>
    <td>
        {{p[0]}}
    </td>
    <td>
        {{p[1]}}
    </td>
    <td>
        {{p[2]}}
    </td>
</tr>

{% endfor %}
</table>

 

Python 多级目录选择

原文:http://www.cnblogs.com/nopnog/p/7065415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!