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 最近写博客的时候偶尔会需要将文件目录结构直观 ...
随机推荐
- Codeigniter CI 框架的一些优化思考
前段时间使用CI做了两个小项目,对CI的流程和设计理念也有了一些新的认识.CI架构的一些基本优化这里就不做介绍了,如搬离system 文件夹等. 最近有一个稍微大一点的系统,也准备拿CI来做.设计时遇 ...
- 再看SpringMVC通过一个DispatcherServlet处理Servlet
初始入口: org.springframework.web.context.ContextLoaderListener org.springframework.web.context.ContextL ...
- bootstrop媒体对象、面板和Well
媒体对象 <div class="media"> <div class="media-left"> < ...
- git push 冲突
git commit -am "test 3" git pull 用自己的:git checkout --ours xxxx路径xxxx 用他人的:git checkout --t ...
- JavaScript中,关于class的调用
PS:class的调用,其实是可以叠加的,当然了这要求样式不同的情况下,如果样式相同,则后一个样式会覆盖前一个样式. 1.举例如下: <div id="test" class ...
- 【Web应用-Web作业】Web 作业无法直接运行 jar 文件
问题描述 在经典管理门户中将直接压缩的 jar 文件打包为 zip 包,上传到 web 作业时报错. 解决方法 jar 文件的运行需要依托于 java 进程,所以在运行 jar 文件时,我们都会以格式 ...
- .Net Mvc 返回Json,动态生成EasyUI Tree
最近做一个项目,开始接触EasyUI,感觉很强大,很适合我这种对前台不是很感冒的人.在学习Tree的过程中,感觉网上的资料挺乱的,很多只是把EasyUI API 抄了一遍.现在把最近这段时间的学到的, ...
- ZOJ 3627 Treasure Hunt II (贪心,模拟)
题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...
- strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用
strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *stringA; @property ...
- fun下载内容批量收集
1.download title and url #!/usr/bin/env python #-*- coding:utf-8 -*- import re, urllib2,threading de ...