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 最近写博客的时候偶尔会需要将文件目录结构直观 ...
随机推荐
- odoo9 部署步详细步骤
sudo apt-get updatesudo apt-get dist-upgrade 一:安装和配置pg sudo apt-get install postgresql sudo su - po ...
- MySql下载地址
因为下载mysql需要注册,很麻烦,记录下下载地址: My sql 5.1.71 http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-5.1.71-win32 ...
- linux分配文件文件夹所属用户及组
ls -l 可以查看当前目录文件.如:drwxr-xr-x 2 nsf users 1024 12-10 17:37 下载文件备份分别对应的是:文件属性 连接数 文件拥有者 所属群组 文件大小 文件修 ...
- [转]POI : How to Create and Use User Defined Functions
本文转自:http://poi.apache.org/spreadsheet/user-defined-functions.html How to Create and Use User Define ...
- 2189 数字三角形W
2189 数字三角形W 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 数字三角形要求走到最后mod 100最大 输入描述 ...
- Android中的ListView属性使用总结
Android中使用ListView控件比较常见,如果能知道常用的一些属性使用,肯定会少很多坑. 1.ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景 ...
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]
2018-06-27 16:43:45.552 INFO 16932 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : ...
- cookie安全
www.baidu.com host 文件 定义 a.baidu.com 为127.0.01 本地编写php程序 读取浏览器发送给 a.baidu.com的cookie 会把 .baidu.com域下 ...
- htmlunit爬取js异步加载后的页面
直接上代码: 一. index.html 调用后台请求获取content中的内容. <html> <head> <script type="text/javas ...
- nuxt 初接触
对于nuxt服务端渲染让人动心的是不会再想vue一样去定义无数的路由了这一点是挺爽的!!! 先直接晒张图 在api这块增加了一个fetch方法 它会在组件每次加载前被调用(即在服务端或切换至目标路 ...