Python 多级目录选择+一键正反排序
效果如图所示,可以根据条件来选择对象
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>
一键正反排序。

主程序端
def onlyone():
order = request.args.get('order')
print order
print '*'*40
sql = 'select * from pc'
if order == 'down':
sql += ' order by nem desc'
elif order == 'up':
sql += ' order by nem'
cur.execute(sql)
res = cur.fetchall() return render_template('pc.html',order=order,pc=res)
html端
{% if order=='up' or not order %}
<button>
<a href='/onlyone?order=down'>up</a>
</button>
{% endif%}
{%if order =='down' %}
<button>
<a href='/onlyone?order=up'>down</a>
</button>
{% endif %}
注意:sql += ' order by nem desc'
or not order
这两种语法需要学习
Python 多级目录选择+一键正反排序的更多相关文章
- 洗礼灵魂,修炼python(78)--全栈项目实战篇(6)—— 多级目录菜单之地址管理系统
相信各位都在在网上买过东西吧?那么今天我的主题就是写个在线购物系统,是不可能的,哈哈(后期确实有这个项目),那么购物都填写过快递地址吧?然后网上查个地址都有地址管理吧? 要求: 1.打印出省.市.县等 ...
- python 一次创建多级目录
python 一次创建多级目录沙漠骆驼:qq音乐import osos.mkdirs('/home/user/app')
- python unittest单元测试框架-3用例执行顺序、多级目录、装饰器、fixtures
1.用例执行顺序 unittest默认会按照ascii码的顺序,依次执行.类名--方法名排序,使用discover也是默认排序.如果不想使用默认排序,就使用testsuite测试集的方式. impor ...
- Python 按当前日期(年、月、日)创建多级目录的方法
先看实际效果,现在时间2018.4.26 使用python脚本按照年月日生成多级目录,创建的目录可以将系统生成的日志文件放入其中,方便查阅,代码如下: #!/usr/bin/env python #c ...
- Python与Go选择排序
#!/usr/bin/env python # -*- coding: utf-8 -*- # 选择排序 # 时间复杂度O(n^2) def selection_sort(array): length ...
- Python实现的选择排序算法原理与用法实例分析
Python实现的选择排序算法原理与用法实例分析 这篇文章主要介绍了Python实现的选择排序算法,简单描述了选择排序的原理,并结合实例形式分析了Python实现与应用选择排序的具体操作技巧,需要的朋 ...
- Python实现拆分多级目录的方式
1 环境 操作系统:Windows10 Python版本:Python3.7 2 简介 实现多级目录差分,举例说明如下: 假设现有的目录结构如下:1.2.2.1.2.2.2.3.2.4.3.4.5.6 ...
- Linux杂谈: 树形显示多级目录--tree
最近写博客的时候偶尔会需要将文件目录结构直观地列出来,例如python的包结构. 于是在网上搜了搜,发现了一个Linux下还不错的工具--tree tree 可以很直观地显示多级目录结构. 1. 安装 ...
- [转帖]Linux杂谈: 树形显示多级目录--tree
Linux杂谈: 树形显示多级目录--tree https://www.cnblogs.com/tp1226/p/8456539.html tree -L 最近写博客的时候偶尔会需要将文件目录结构直观 ...
随机推荐
- Retrofit实现Delete请求
//设置取消关注 @Headers("Content-Type:application/x-www-form-urlencoded") @HTTP(method = "D ...
- C#连接Oracle中文乱码问题解决方法
1.打开注册表:开始-运行-regedit HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/KEY_OraDb11g_home1/OLEDB 在右侧点鼠标右键- ...
- C# (Cookie)基本操作
在Common中新建一个CookieHelper,全局调用 using System; using System.Collections.Generic; using System.Linq; usi ...
- dubbo源码阅读之集群(故障处理策略)
dubbo集群概述 dubbo集群功能的切入点在ReferenceConfig.createProxy方法以及Protocol.refer方法中. 在ReferenceConfig.createPro ...
- 洛谷 P1873 砍树
砍树 二分答案,难度较低. #include <iostream> #include <cstdio> #include <algorithm> using nam ...
- 如何加快HTML页面加载速度
1. 页面减肥 a. 页面的肥瘦是影响加载速度最重要的因素. b. 删除不必要的空格.注释. c. 将inline的script和css移到外部文件. d. 可以使用HTML Tidy来给HTML减肥 ...
- printf 遇到bash重定向
在printf之前添加:setvbuf(stdout,NULL,_IONBF,0);设置缓冲区为空. 在每句printf之后添加:fflush(stdout); 方法一: 1 2 3 4 5 6 7 ...
- 使用POI创建word表格-在表格单元格中创建子表格
要实现的功能如下:表格中的单元格中有子表格 实现代码如下: XWPFParagraph cellPara = row.getCell(j).getParagraphArray(0); //row.ge ...
- jquery 不支持$.browser
if (!$.browser) { $.browser = { mozilla : /firefox/.test(navigator.userAgent.toLowerCase()), webkit ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource
spring boot web项目运行时提示如下错误 org.springframework.beans.factory.BeanCreationException: Error creating b ...