<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>落 &#187; Python</title>
	<atom:link href="http://liluo.org/class/development/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://liluo.org</link>
	<description>落就是一道风景线……</description>
	<lastBuildDate>Tue, 09 Aug 2011 11:22:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用PIL给图片添加水印</title>
		<link>http://liluo.org/2011/08/%e4%bd%bf%e7%94%a8pil%e7%bb%99%e5%9b%be%e7%89%87%e6%b7%bb%e5%8a%a0%e6%b0%b4%e5%8d%b0/</link>
		<comments>http://liluo.org/2011/08/%e4%bd%bf%e7%94%a8pil%e7%bb%99%e5%9b%be%e7%89%87%e6%b7%bb%e5%8a%a0%e6%b0%b4%e5%8d%b0/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 11:19:31 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[PIL]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=700</guid>
		<description><![CDATA[前几天在做一个给指定相册添加水印的功能，使用的是PIL(Python Image Library)。
先去看一下网上，找到这篇：Watermark with PIL (Python recipe) 于是，处理水印的核心代码就差不多有了～

当然，问题也接着来了，首先就是拿到的图片文件和水印文件。我这边得到上传图片文件基本上会是文件二进制数据流或者由Flash post过来的application/octet-stream类型的二进制数据流，并不能像参考中的代码使用指定路径拿到文件，所以数据流进行处理：
import Image, ImageEnhance
from cStringIO import StringIO
img = Image.open(StringIO(img_data)) # img_data 是post过来的数据流
这样就可以拿到一个Image对象了。再使用类似参考代码对它进行水印处理。
然后在上传图片的时候，依然使用原来的机制，这里再把加过水印的数据流丢出去：
new_img = StringIO()
img.save(new_img, img_format, quality=100) # quality来指定生成图片的质量，范围是0～100
reutrn new_img.getvalue()
代码上线不久之后，就有同事反映说有png图片上传之后会原图会变掉，我拿png去上传之后效果正常，于是把他那张图拿过来测试，果然报错。后来发现他那张png使用的模式是'RGBA', 而我们一般情况下的png或者gif模式是'P'，会不会是因为图片模式问题呢？
测试：
img = Image.open('/Users/luo/p.png')
img.show()
在这个时候图片就已经被奇怪的变化了 ＃＃
后来多次尝试发现在 img.save() 时指定format='PNG'时效果正常，于是另加上了mode判断：
if img.mode != 'RGBA':
img_format = 'JPEG'
else:
img_format = 'PNG'
然后在保存时
img.save(new_img, img_format, quality=100)
本地环境测试ok，然后代码提交～
完整代码：
from cStringIO import StringIO
import Image, ImageEnhance
LEFT_TOP     = 'lt'
LEFT_BOTTOM  = 'lb'
RIGHT_TOP    = 'rt'
RIGHT_BOTTOM = 'rb'
WIDTH_GRID = [...]]]></description>
		<wfw:commentRss>http://liluo.org/2011/08/%e4%bd%bf%e7%94%a8pil%e7%bb%99%e5%9b%be%e7%89%87%e6%b7%bb%e5%8a%a0%e6%b0%b4%e5%8d%b0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Memcached 安装、使用（Python操作）以及常用方法</title>
		<link>http://liluo.org/2011/03/memcached-install-python-use/</link>
		<comments>http://liluo.org/2011/03/memcached-install-python-use/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 11:03:12 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Memcached]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=644</guid>
		<description><![CDATA[Memcached官网 memcached.org
简单介绍：memcached很强大，它可以支持分布式的共享内存缓存，大型站点都用它。对小站点来说，有足够内存的话，使用它也可以得到超赞的效果。
使用目的：由前面的介绍看到，大家使用它都是为了速度，不过我却是为了解决Session在不同浏览器中偶尔丢失的数据。其实也不能怪浏览器啦，主要是我需要一个dict类型的session，哈哈。
安装
Linux
安装包
对于大多数Linux发行版本来说，可以使用官方推荐的方法：
Debian/Ubuntu
apt-get install memcached
Redhat/Fedora/CentOS
yum install memcached
源码安装(CentOS 5.5)
1、下载libevent（依赖） 和memcached
分别到以下引用地址下载最新版本：
引用地址 http://www.monkey.org/~provos/libevent/ 
引用地址:http://code.google.com/p/memcached/downloads/list
2、安装ibevent（依赖） 和memcached
libevent(目前最新是libevent-2.0.10-stable.tar.gz，请注意版本号)
tar xvf libevent-2.0.10-stable.tar.gz
cd libevent-2.0.10-stable
./configure --prefix=/usr/local/libevent/
make
make install
接着，ls /usr/local/libevent/lib，将查看到的第一个类似libevent-X.X.so.X
ln -s /usr/local/libevent/lib/libevent-2.0.so.5  /lib/libevent-2.0.so.5
memcached (目前最新是1.4.5，请注意版本号)
tar zxvf  memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
make 
make install
3、启动memcached
启动参数说明(这是我是复制粘贴的，如有错误请指正)：
-d 选项是启动一个守护进程
-m 是分配给Memcache使用的内存数量，单位是MB，默认64MB
-M return error on memory exhausted (rather than removing items)
-u 是运行Memcache的用户，如果当前为root 的话，需要使用此参数指定用户
-l 是监听的服务器IP地址，默认为所有网卡
-p 是设置Memcache的TCP监听的端口，最好是1024以上的端口
-c 选项是最大运行的并发连接数，默认是1024
-P 是设置保存Memcache的pid文件
-f chunk size growth factor (default: 1.25)
-I Override the size of [...]]]></description>
		<wfw:commentRss>http://liluo.org/2011/03/memcached-install-python-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python操作Excel读写(使用xlrd和xlrt)</title>
		<link>http://liluo.org/2011/01/python%e6%93%8d%e4%bd%9cexcel%e8%af%bb%e5%86%99%e4%bd%bf%e7%94%a8xlrd%e5%92%8cxlrt/</link>
		<comments>http://liluo.org/2011/01/python%e6%93%8d%e4%bd%9cexcel%e8%af%bb%e5%86%99%e4%bd%bf%e7%94%a8xlrd%e5%92%8cxlrt/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 13:03:14 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[xlrd]]></category>
		<category><![CDATA[xlwt]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=629</guid>
		<description><![CDATA[传说中python操作ms office功能最强大的是win32com（据说只要人工能操作的它都能实现，未尝试尚不知道真假），不过对于比较简单的需求显得有些小题大作。那么来看下简单的，分别是xlrd和xlwt模块。
xlrd
http://pypi.python.org/pypi/xlrd
简单使用

导入
import xlrd
打开excel
data = xlrd.open_workbook('demo.xls') #注意这里的workbook首字母是小写
查看文件中包含sheet的名称
data.sheet_names()
得到第一个工作表，或者通过索引顺序 或 工作表名称
table = data.sheets()[0]
table = data.sheet_by_index(0)
table = data.sheet_by_name(u'Sheet1')
获取行数和列数
nrows = table.nrows
ncols = table.ncols
获取整行和整列的值（数组）
table.row_values(i)
table.col_values(i)
循环行,得到索引的列表
for rownum in range(table.nrows):
print table.row_values(rownum)
单元格
cell_A1 = table.cell(0,0).value
cell_C4 = table.cell(2,3).value
分别使用行列索引
cell_A1 = table.row(0)[0].value
cell_A2 = table.col(1)[0].value
简单的写入
row = 0
col = 0
ctype = 1 # 类型 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error
value = 'lixiaoluo'
xf = 0 # 扩展的格式化 [...]]]></description>
		<wfw:commentRss>http://liluo.org/2011/01/python%e6%93%8d%e4%bd%9cexcel%e8%af%bb%e5%86%99%e4%bd%bf%e7%94%a8xlrd%e5%92%8cxlrt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CPS系统开发(PyLons项目)</title>
		<link>http://liluo.org/2010/12/cps%e7%b3%bb%e7%bb%9f%e5%bc%80%e5%8f%91pylons%e9%a1%b9%e7%9b%ae/</link>
		<comments>http://liluo.org/2010/12/cps%e7%b3%bb%e7%bb%9f%e5%bc%80%e5%8f%91pylons%e9%a1%b9%e7%9b%ae/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:04:55 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Pylons]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=622</guid>
		<description><![CDATA[最近在埋头写CPS系统，到现在为止程序开发已经全部完成，剩下的由美工来设计页面和CSS（感觉很奇怪吧，项目开发完了才来这项？没办法，公司小，老板又不肯听解释）。嗯，系统和GPS只差一个字母，好玩吧？其实没有，一点也不好玩。 
CPS中文就是职业定位系统，是现在公司目前的主要业务，目前使用的版本是公司股东那边负责使用java开发的　（地址http://cps.hbbcareer.com界面很纠结是吧？哈哈，当时是由我乱拼出来的）。简单的来描述一下系统流程就是：首先由某公司或者个人买单，然后测评用户做选择题，然后得到一份报告，内容就是个人优势劣势分析，主观认知与客观事实的差异以及匹配的行业和职业。当然了，这样来讲似乎太简化了，嘿嘿。
系统依然是使用Python开发（其他我也不会……），其中：
服务器CentOS5.5
数据库Postgresql 9.0
Web Server: Nginx 8.49
Python版本 　2.6.5
Framework　　PyLons 1.0
Template　　 mako
Excel读写　　xlrd、xlwt
生成图表　　matplotlib
对图片操作　Pil
生成PDF　　reportlab
在线支付使用网银在线，参照其PHP版本的接口改写成Python版本
项目中费时最多的就是图表和PDF文档的生成，其中中文字符、字号大小，格式排版等问题有点小纠结，不过掌握之后觉得也蛮简单，这几天抽出时间总结一下对Excel读写操作的xlrd,rlwt以及matplotlib和reportlab的基本使用。
最后放张缩略图

]]></description>
		<wfw:commentRss>http://liluo.org/2010/12/cps%e7%b3%bb%e7%bb%9f%e5%bc%80%e5%8f%91pylons%e9%a1%b9%e7%9b%ae/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>单元测试(python\django\pylons)</title>
		<link>http://liluo.org/2010/11/pythondjangopylons-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95/</link>
		<comments>http://liluo.org/2010/11/pythondjangopylons-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 09:44:09 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Pylons]]></category>
		<category><![CDATA[Unit]]></category>
		<category><![CDATA[单元测试]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=614</guid>
		<description><![CDATA[清风老师提到的第2点——单元测试，总结一下。
其实我的主要目的是想Django的单元测试，由于Django使用了Python的标准模块doctest和unittest，所以我觉得有必要了解一下Python的单元测试。另外还有就是比较欣赏的PyLons框架的单元测试内容。
一、Python单元测试doctest,unittest（PyUnit） 
1、doctest 框架 
在Python中doctest就是把程序中的docstring作为范例来运行的一个框架，docstring可以由普通部分和执行部分组成，普通部分等同于原来的文字说明，执行部分由'&#62;&#62;&#62;'（python shell提示符）或'...'提示符区分。程序员可以通过手工编写可预测的执行部分，也可以通过拷贝复制python交互式shell中的输入和输出简单的形成执行部分，doctest搜寻存在与各个模块，类和函数中的docstring,把每个可执行部分当成一次范例运行，再把实际运行值和期望值的对照作为一次运行结果。
我大致看了一下doctest，感觉还是比较容易上手的，另外还有一个优点就是可以很方便的生成文档。由于比较简单，就不多作介绍，具体可参考：
http://docs.python.org/library/doctest.html
2、unittest(PyUnit框架)
unittest模块,也就是PyUnit（全称：The Python unit testing framework）是Kent Beck和Erich Gamma这两位聪明的家伙所设计的 JUnit 的Python版本，自从Python2.1版本以后，PyUnit已经被加入到Python标准库（也就是unittest）。
简单实例：
import unittest            # 导入单元测试模块
from demo import Demo
class DemoTests(unittest.TestCase):  # 由TestCase派生类
def setUp(self): # 开始单元测试准备工作，初始化环境
pass
def tearDown(self): # 完成单元测试收尾，清除环境
pass
def testAdd(self): # 完成单元测试收尾，清除环境
pass
def suite():
suite = unittest.TestSuite()
suite.addTest(Demo('testAdd'))
return suite
if __name__ == "__main__":
unittest.TextTestRunner().run(suite())
参考：
http://docs.python.org/library/unittest.html
http://pyunit.sourceforge.net/pyunit_cn.html
二、Django单元测试  
Django中的单元测试有2种:Doctests、Unit tests，分别对应Python标准库doctest和unittest，可想而知其用法也是大同小异。
1、Doctests
对于一个Django应用程序，它会在应用程序目录下的models.py和tests.py两个文件去寻找可运行的doctests。需要注意的是，在models.py的doctest当中，test runner自己会建立单独的测试用数据库。也就是说，任何涉及数据库访问的测试——如创建并保存了模型的实例——都不会对你实际使用的数据库产生影响，因为测试时会使用它自己创建的单独的数据库。同时，在doctests运行期间，你实际使用的数据库也不会刷新。所以，如果你的测试依赖于一些特定的状态，那么你就应该考虑显式操作你实际使用的数据库，或者读取一个fixture（伪造的可用数据）。（后面会有关于fixtures更详细的介绍。）请注意，要使用此功能，作为数据库用户的Django必须要有可 CREATE DATABASE 的权限。
如果感觉 doctest 更显得 “pythonic”（它的设计目的本来就是使编写测试尽可能的简单化，而不用专门去写一些类，函数之类的东西。你只需要像写注释一样把测试功能写在docstrings里就可以了。这种做法的一个额外好处，就是测试可以直接作为文档的一部分）或者如果是刚刚接触测试工作的人，那么使用doctests会更快地入门单元测试。
关于doctest细节，同样可参考 http://docs.python.org/library/doctest.html
2、Unit tests
相较于doctests，unit tests使用了另外一种方式定义测试，一种基于“类”的实现。像doctests一样，对于一个Django应用程序，test runner会在两个地方寻找unit tests：应用程序目录下的models.py和tests.py。运行测试 时，测试工具默认的行为是在 models.py 和 tests.py 中找到所有的测试用例（ unittest.TestCase 的所有子类），然后自动将这些测试用例构建成一个测试集，然后开始跑这个测试集。
如果在 models.py 或 tests.py 中定义了一个名为 suite() 的函数，那么Django的test runner将会调用此函数来构建本模块的测试集。这也是被 推荐使用 的测试用例的组织方法。
关于unit [...]]]></description>
		<wfw:commentRss>http://liluo.org/2010/11/pythondjangopylons-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PostgreSQL 9.0 安装乱乱记</title>
		<link>http://liluo.org/2010/11/postgresql-9-0-%e5%ae%89%e8%a3%85%e4%b9%b1%e4%b9%b1%e8%ae%b0/</link>
		<comments>http://liluo.org/2010/11/postgresql-9-0-%e5%ae%89%e8%a3%85%e4%b9%b1%e4%b9%b1%e8%ae%b0/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 02:24:21 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Postgresql]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=606</guid>
		<description><![CDATA[PostgreSQL 9已经发布了，我属于新版本控，于是计划着在VPS( win server 2003)和服务器(CentOS 5.5)上安装，先不讲过程，结果是服务器上已成功安装，VPS主动放弃。在些提醒各位，PostgreSQL 9安装很纠结，选择需慎重。

一、VPS（win server 2003）
直接在官网下载 win安装包.exe文件,按照8.4版本的习惯一路直下，在安装完成的时候出现 “ Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed.” GG一下，看到有人讲在非英文系统下安装时Local选择非默认语言，如Singapore或c（别听那些不靠谱的说选Chinese，在9.0版本中压根没那选项）。于是把自己电脑上（ win xp）的8.4卸载，重新安装选择Singapore（新加坡，对中文支持比较好），依然一路直下，OK搞定。然后把VPS卸载重新安装，依然出错，泪流满面……把公司另台电脑格掉装上win server 2003，安装时local选Singapore，结果成功。后来又在VPS上尝试local时选C或者其他，依然失败，然后又拿8.4甚至8.3版本安装失败依然。在其他win系统（包括同版本的win server 2003）中可正常安装，好吧VPS，到期我就换掉你丫的。
win正常安装pg9请注意：中文版系统安装时local一定选择非默认语言。



二、服务器（CentOS 5.5）
一直想给服务器（使用CentOS）装上PostgreSQL，最初的时候使用yum，结果一看是在Down 8.3版本（丫的先不说9.0版已经横空出世，8.4版可出来N久了），直接ctrl+C。
之后参照鱼哥(smallfish)的教程（点击）下载了并安装了pg9初始化时:
service postgresql initdb
Usage: /etc/init.d/postgresql {start&#124;stop&#124;restart&#124;reload&#124;status}
@##@！￥￥@#什么东东，可以使用了吗？
service postgresql start
Starting PostgreSQL: ok
service postgresql stop
Stopping PostgreSQL: pg_ctl: PID file "/usr/local/pgsql/data/postmaster.pid" does not exist
Is server running?
什么状况？欲哭无泪……于是等yum安装Pg版本升级到9.0。前天几发现已经到9.0了:
yum postgresql [...]]]></description>
		<wfw:commentRss>http://liluo.org/2010/11/postgresql-9-0-%e5%ae%89%e8%a3%85%e4%b9%b1%e4%b9%b1%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Django中使用多线程发送邮件</title>
		<link>http://liluo.org/2010/11/django%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6/</link>
		<comments>http://liluo.org/2010/11/django%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 05:36:21 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=600</guid>
		<description><![CDATA[当然了，网上关于Django发送邮件的资料蛮多的，但是基本上都是使用send_mail()。于是我也屁颠屁颠的找到某一个版本使用，邮件发送是成功了，但那速度实在是很蜗牛。刚开始以为是开发环境的原因，结果到了服务器的生产环境依然需要等到花都谢了，于是乎Google之，无果。豆瓣上有一仁兄给了个链接（在这里），参考之另加使用模板文件，于是生成又一个小异的版本。
1、settings.py 增加Email设置


#mail
EMAIL_HOST = 'smtp.gmail.com'                   #邮件smtp服务器
EMAIL_PORT = '25'                                        #端口
EMAIL_HOST_USER = 'code***@gmail.com'  #邮件账户
EMAIL_HOST_PASSWORD = '*********'      #密码
EMAIL_USE_TLS = False
2、views.py 发送邮件


from django.core.mail import EmailMultiAlternatives
from django.template import loader
from settings import [...]]]></description>
		<wfw:commentRss>http://liluo.org/2010/11/django%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Django使用内置paginator类分页</title>
		<link>http://liluo.org/2010/10/django%e4%bd%bf%e7%94%a8%e5%86%85%e7%bd%aepaginator%e7%b1%bb%e5%88%86%e9%a1%b5/</link>
		<comments>http://liluo.org/2010/10/django%e4%bd%bf%e7%94%a8%e5%86%85%e7%bd%aepaginator%e7%b1%bb%e5%88%86%e9%a1%b5/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 07:29:39 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=590</guid>
		<description><![CDATA[Django分页是比较方便的，我们可以使用内置的一个paginator类。
这里以查询图书为例，以下是主要代码：
---------------------------------------------------------------------------------------------------
views.py
#导入方法PageNotAnInteger, Paginator, InvalidPage, EmptyPage
from django.core.paginator import PageNotAnInteger, Paginator, InvalidPage, EmptyPage
def  list(request):
books = Book.objects.all() #之前需要从models中导入Book
after_range_num = 5        #当前页前显示5页
befor_range_num = 4       #当前页后显示4页
try:                     #如果请求的页码少于1或者类型错误，则跳转到第1页
page = int(request.GET.get("page",1))
if page &#60; 1:
page = 1
except ValueError:
page = 1
paginator = Paginator(books,2)   # 设置books在每页显示的数量，这里为2
try:                     #跳转到请求页面，如果该页不存在或者超过则跳转到尾页
books_list = paginator.page(page)
except(EmptyPage,InvalidPage,PageNotAnInteger):
books_list = paginator.page(paginator.num_pages)
if page &#62;= after_range_num:
page_range = paginator.page_range[page-after_range_num:page+befor_range_num]
else:
page_range = paginator.page_range[0:int(page)+befor_range_num]
return render-to_response('book_list.html',{'books':books_list,'page_range':page_range})
-----------------------------------------------------------------------------------------------
Templates 视图
book_list.html
{% for book in books.object_list %}
{{ book.id [...]]]></description>
		<wfw:commentRss>http://liluo.org/2010/10/django%e4%bd%bf%e7%94%a8%e5%86%85%e7%bd%aepaginator%e7%b1%bb%e5%88%86%e9%a1%b5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pylons framework 笔记(1)</title>
		<link>http://liluo.org/2010/09/pylons-framework-%e7%ac%94%e8%ae%b01/</link>
		<comments>http://liluo.org/2010/09/pylons-framework-%e7%ac%94%e8%ae%b01/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 14:51:40 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Pylons]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=584</guid>
		<description><![CDATA[使用Django已经有蛮长一段时间，感觉还不错，不过还是想多了解下其他framework来做对比更加客观。于是有看web2py,感觉很怪异，web.py却又不怎么喜欢，于是的于是目前关注Pylons和Bfg。貌似Pylons的资料比bfg更多一些，而且貌似有号称python 中的ror，于是先拿它下手，当然Bfg也会在未来尝试。好吧，记录下Pylons，系统 OpenSUSE11.3，参考 http://pylonshq.com/docs/en/1.0/gettingstarted/#installing

1、安装
题外话：自从使用setuptools（也就是easy_install.py，可在官网down最新版本）之后再也不想去down去setup.py install，因为easy_install确实有够方便快捷。感觉像Ruby里的gem，我对ror不太了解，讲错的话别介意。
安装pylons:  easy_install Pylons
2、创建hello,world
就像之前有讲过的一样，hello world又要经典重现了。
paster create -t pylons helloworld
紧接着让选择模板，选择默认的mako,再然后是选择是否启用SQLAlchemy，默认是否，好吧，这里也继续保持默认。
现在基于pylons的helloworld的项目已经建立，有兴趣的话进入项目目录看下结构吧。
3、启动
cd helloworld进入项目目录，使用
paster serve --reload development.ini
启动这个简单的project，其中--reload development.ini表示自动加载更新。
现在打开 http://127.0.0.1:5000 即可看到默认页面，蛮酷的效果。
4、新建一个controller
paster controller hey
系统自动生成hey.py和test_hey.py两个文件。
现在打开http://127.0.0.1:5000/hey/index 即可看到hello world。
5、新建mako模板
$helloword# vim helloword/templates/hey.mako
输入以下文字：
Hello World, the environ variable looks like: &#60;br /&#62;

${request.environ}
然后把 hey.py中的 return "hello world"注释掉，
把#return render('/hey.mako')注释取消：
def index(self):
        # Return a rendered template
     [...]]]></description>
		<wfw:commentRss>http://liluo.org/2010/09/pylons-framework-%e7%ac%94%e8%ae%b01/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CentOS 5.5 中 Python 升级到 2.6.5</title>
		<link>http://liluo.org/2010/08/centos-5-5-%e4%b8%ad-python-%e5%8d%87%e7%ba%a7%e5%88%b0-2-6-5/</link>
		<comments>http://liluo.org/2010/08/centos-5-5-%e4%b8%ad-python-%e5%8d%87%e7%ba%a7%e5%88%b0-2-6-5/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 08:38:49 +0000</pubDate>
		<dc:creator>落落</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[CentOS]]></category>

		<guid isPermaLink="false">http://liluo.org/?p=570</guid>
		<description><![CDATA[前天公司购买一台服务器(放置在外高桥电信机房，跑的是JSP的应用)，不想在服务器上使用盗版的Win server(当然也是为了公司节省软件许可费用)，于是安装了 CentOS 5.5(貌似是目前比较新的版本？)。因为比较喜欢Python，所以就随手敲入python，居然是2.4.3的版本，阿门。于是的于是就有了下面给Python升级的过程(CentOS 5.5 中实验成功，其他发行版本Linux可作参考)。
1、下载
wget http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2
2、解压
tar jxvf Python-2.6.5.tar.bz2
3、编译安装
cd Python-2.6.5
./configure
make &#38;&#38; make install
Python 默认安装目录在/usr/local/lib/python2.6
查看一下刚才安装的版本/usr/local/bin/python -V，看到了2.6.5吧
4、更改系统默认版本
之前查看版本使用 /usr/local/lib/python2.6 -V，现在来把系统默认的Python指向刚才安装的Python2.6。
(如果有人问为什么不把2.4.3卸载呢？呃，貌似网上有讲yum是基于2.4.3，所以我也就没那样折腾)
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python2.6 /usr/bin/python
敲入 python -V 查看是否成功。
5、修复不能正常工作的yum
在完成了上面4步之后，如果有使用yum的话会发现出错，这是因为yum 依赖2.4.3而现在默认的 Python 版本是2.6.5。
vim /usr/bin/yum
将首行显示的 !#/usr/bin/python 修改为 !#/usr/bin/python2.4
保存搞定。
]]></description>
		<wfw:commentRss>http://liluo.org/2010/08/centos-5-5-%e4%b8%ad-python-%e5%8d%87%e7%ba%a7%e5%88%b0-2-6-5/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

