
python
文章平均质量分 72
不懂别瞎说
这个作者很懒,什么都没留下…
展开
-
django 自定义截取中文的过滤器
django 自带的模板过滤器truncatewords和truncatewords_html 都是不支持中文的,前者是截取不带html标签的内容,后者截取带html标签的内容。为了达到截取中文的目的,按照truncatewords和思路重新编写了字符截取工具 这个新的truncatewords函数是从带html标签的内容或不带html内容中截取字符的,中英文皆可,截取之后会去掉原有的标签...2012-04-29 10:35:03 · 514 阅读 · 0 评论 -
mongodb 查询优化技巧一
mongodb天生不支持多表关联查询,所有复杂的查询都交给了app来处理,这样为了减少在mongodb的查询就要在app上下功夫了 images = mongo.image.find({'uid':1,'atime':1,'views':1,'rank':1},skip=0,limit=10) 这条语句查询图片的元信息,但是我们还需要创建图片的作者的信息 为了减少与mong...2012-08-01 16:44:08 · 393 阅读 · 0 评论 -
python对象引用的一个经典例子
number_list = []tmp={}for i in range(3): number = random.randint(10,20) if number: tmp['num']=number print 'number is ',tmp['num'] print 'tmp id is',id(...2012-07-30 22:06:38 · 146 阅读 · 0 评论 -
python--mongodb 翻页工具
由于mongodb的翻页使用的是skip,而不是limit start,end,所以计算的应该是每页应该skip的数据,以下分页工具可以完成mongodb的分页要求 #turn page util class Paginator(object): def __init__(self,total_records=None,per_page=None): ...2012-07-28 00:17:11 · 290 阅读 · 0 评论 -
python 分页工具
分页工具基础类 #分页工具from math import ceil,floorclass InvalidPage(Exception): passclass PageNotAnInteger(InvalidPage): passclass EmptyPage(InvalidPage): passclass...原创 2012-04-05 23:07:58 · 181 阅读 · 0 评论 -
python 正则表达式匹配中文
网上的一篇文章,做了整理,作者已无从考证,谢谢了 s="""en: Regular expression is a powerful tool for manipulating text. zh: 中文 jp: 正規表現は非常に役に立つツールテキストを操作することです。 jp-char: あアいイうウえエおオ kr:정규 표현식은 매우 유용한 도구 텍스트를 조...原创 2012-04-05 10:49:20 · 347 阅读 · 0 评论 -
转载:Mongodb无法正常启动的解决方案
Mongodb无法正常启动的解决方案转载This evening I tried to connect to my MongoDB instance using the command line mongo tool and got the following error message: Error: couldn't connect to server 127.0.0.1...原创 2012-07-12 16:39:53 · 302 阅读 · 0 评论 -
ubuntu 安装MySQL-python 各种错误解决方案
首先假定你的ubuntu已经安装了MySQL linux版本的server和client,这个可以在ubuntu的软件管理中心获得,(请注意MySQL 的版本,因为MySQL-python对不同版本的MySQL有不同的支持),并且mysql已经可以使用,可以在终端使用mysql命令进行测试 然后把下载的MySQL-python 尽量放在 usr/local/src 目录下 运行如...原创 2012-02-23 12:09:05 · 290 阅读 · 0 评论 -
django book 2.0 中文版
the django 2.0 的中文版译本打包原创 2012-02-23 09:51:54 · 137 阅读 · 0 评论 -
Installing Django with Apache and mod_wsgi on Ubuntu 10.04
Installing Django with Apache and mod_wsgi on Ubuntu 10.04By Kevan Stannard | Published: December 11, 2010Step by step instructions for installing Django with Apache and mod_wsgi ...原创 2012-05-04 16:51:59 · 160 阅读 · 0 评论 -
使用python字典动态组合mongo查询语句
在使用myql的时候,由于使用的传统的关系型数据库,可以自己自由拼凑sql来进行查询, 这为多条件的组合查询带来了便利,而mongodb由于其特殊性,需要自己动手利用其特点来组合我们的查询语句 比如参数每个的值可以是true,false或者None, not None,这样他们的组合多样性导致需要写不同的查询才能完成 以python为例,我们先使用pymongo链接mong...2012-08-02 22:27:54 · 586 阅读 · 0 评论