<?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>HackGou In Lamp&#124;憨狗点灯 &#187; django</title>
	<atom:link href="http://hackgou.itbbq.com/category/django/feed" rel="self" type="application/rss+xml" />
	<link>http://hackgou.itbbq.com</link>
	<description>LAMP开放的是代码，是接口，是互操作性</description>
	<lastBuildDate>Thu, 15 Jul 2010 14:23:06 +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>再次质疑Django+M od_python时对环境 变量的处理</title>
		<link>http://hackgou.itbbq.com/%e5%86%8d%e6%ac%a1%e8%b4%a8%e7%96%91djangom-od_python%e6%97%b6%e5%af%b9%e7%8e%af%e5%a2%83-%e5%8f%98%e9%87%8f%e7%9a%84%e5%a4%84%e7%90%86.html</link>
		<comments>http://hackgou.itbbq.com/%e5%86%8d%e6%ac%a1%e8%b4%a8%e7%96%91djangom-od_python%e6%97%b6%e5%af%b9%e7%8e%af%e5%a2%83-%e5%8f%98%e9%87%8f%e7%9a%84%e5%a4%84%e7%90%86.html#comments</comments>
		<pubDate>Thu, 17 Jan 2008 04:12:01 +0000</pubDate>
		<dc:creator>HackGou</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/%e5%86%8d%e6%ac%a1%e8%b4%a8%e7%96%91djangom-od_python%e6%97%b6%e5%af%b9%e7%8e%af%e5%a2%83-%e5%8f%98%e9%87%8f%e7%9a%84%e5%a4%84%e7%90%86.html</guid>
		<description><![CDATA[今天在升级一个django开发的系统到V2的时候，
发现~/无法正确的展开成 /home/hackgou.(apache是以hackgou帐号执行的，)
也不会展开成/root（apache是以root启动的） 觉得非常奇怪，
就算是用os.path.expanduser(&#8216;~/&#8217;)也无济于事。 于是怀疑是os.envrion['HOME']不对，
因为expanduser是需要这个变量来展开~/的。 于是使用setenv HOME /home/hackgou/ 可是也不工作，
后来在django/core/handlers/modpython.py的ModPythonHandler中 发现Django开发组已经注意到，
mod_python不理会apache的setENV指令：
 # mod_python fakes the environ, and thus doesn&#8217;t process SetEnv.  This fixes that
os.environ.update(req.subprocess_env)
但是这个和SetEnv DJANGO_SETTINGS_MODULE app.settings 自相矛盾矛盾，真晕，
自己不设置正确的，也不搭理管理员指定的，怎么办？
后来在http://code.google.com/p/modwsgi/wiki/ApplicationIssues找到一些类似的情况，
 提到sudo的时候有bug，会导致HOME和root启动的HOME不一样，太好了，我就要这样的bug。
设置hackgou账号的sudo权限，然后用sudo来启动apache，果然所有的expanduser(&#8216;~/&#8217;)都顺利。
 除此之外， 文中提到
import os, pwd os.environ["HOME"] = pwd.getpwuid(os.getuid()).pw_dir
这样的代码，似乎可以解决这个问题，神啊，我很反感这种做法：
 1.django中似乎没有地方可以放置这样的需要这个APP都需要的代码，我的DRY啊
2.Django修改环境变量似乎成了习惯，之前碰到个TIME_ZONE的问题，就是因为修改了APACHE的环境变量，
导致 别的应用环境受到污染，要知道一个apache进程是很多应用共享的， 除了Djano还有别的应用，
比如别的Django应用或者PHP，都有可能在一个相同的APACHE进程空间中处理，
说有可能是因为apache本身的一些设置会出现这些差别，跟py没有关系， 这样会导致他们的工作环境受到污染。
这似乎没有好的方法可以解决这个问题， 对Django或者说对mod_python 的这种拖泥带水的做法感觉非常的不爽。
也不知道有没有更好的更彻底的解决方法？
如果谁知道，能够告诉我那是最好不过的了
]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/%e5%86%8d%e6%ac%a1%e8%b4%a8%e7%96%91djangom-od_python%e6%97%b6%e5%af%b9%e7%8e%af%e5%a2%83-%e5%8f%98%e9%87%8f%e7%9a%84%e5%a4%84%e7%90%86.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>让easy_install构造自己的py thon小天地</title>
		<link>http://hackgou.itbbq.com/%e8%ae%a9easy_install%e6%9e%84%e9%80%a0%e8%87%aa%e5%b7%b1%e7%9a%84py-thon%e5%b0%8f%e5%a4%a9%e5%9c%b0.html</link>
		<comments>http://hackgou.itbbq.com/%e8%ae%a9easy_install%e6%9e%84%e9%80%a0%e8%87%aa%e5%b7%b1%e7%9a%84py-thon%e5%b0%8f%e5%a4%a9%e5%9c%b0.html#comments</comments>
		<pubDate>Mon, 18 Dec 2006 09:18:02 +0000</pubDate>
		<dc:creator>HackGou</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[dreamhost]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/%e8%ae%a9easy_install%e6%9e%84%e9%80%a0%e8%87%aa%e5%b7%b1%e7%9a%84py-thon%e5%b0%8f%e5%a4%a9%e5%9c%b0.html</guid>
		<description><![CDATA[在linux环境中玩、用python，常常需要安装额外的一些python lib
但是由于权限的问题，我们一般是无法往系统中/usr/local之类的目录
里面写东西的，而这些额外的lib又非得需要一个site-packages目录来安装
不可，虽然可以指定pure-lib之类的参数，但是很多时候还是会出错，尤其是现在很多python
lib都是使用的setuptools来生成安装包，更是如此要求了，
[gavin@Korea downloads]$ ll /usr/local/python24/lib/python2.4/site-packages/
total&#160;24
drwxr-xr-x&#160; 2&#160;root root 4096 Dec 18 16:05 PIL
-rw-r--r--&#160; 1&#160;root root&#160; &#160; 4 Dec 18 16:05 PIL.pth
-rw-r--r--&#160; 1&#160;root root&#160; 119 Dec 18 14:59 README
这可麻烦了，每个文件都是root的，旁人只能看，
其实这儿有个很好的解决方法：在自己的目录下面,安装一个虚拟的python：
在自己的目录下面建立一些lib、include等等的目录，构成一个独立的python小天地，这样，系统范围内没有的python库，就可以自己动手安装在自己的小天地中
安装，既不需要root权限，又可以满足自己的需求，一举两得。
这些安装步骤，当然不需要我们重新造轮子，下载
http://peak.telecommunity.com/dist/virtual-python.py
这个脚本，使用你喜欢的python（有的环境提供多个python版本，比如DreamHost）
执行一下这个virtual-python.py，就会自动在~/下面建立所需的目录(~/bin、/lib、
~/include），以及所需python版本，以及创建python所依赖的其他的.h头文件、.py库文件等等软链接，而且会在～/bin/下面copy一个可以执行的python文件，以后直接使用这个~/bin/python来执行py程序，它就会自动找到额外安装在小天地中的那些python库了。如果觉得把bin、lib、include放在~下面不好可以给virtual-python.py指定一个&#8211;prefix参数：
[gavin@Korea bin]$ python24 virtual-python.py --prefix=~/python-lib
[gavin@Korea&#160;bin]$ pwd
/home/gavin/python-lib/bin
[gavin@Korea&#160;bin]$ ll
total&#160;2360
-rwxrwxr-x&#160; 1&#160;gavin gavin 2404367 Dec 18 16:53 python
会把那些bin、lib、include安装在~/python-lib下面，
这下，你就可以使用easy__install来安装自己额外需要的那些库了，
不过等等先，由于此时使用的easy_install是系统范围的，所以它会把东西安装在
/usr/local之类的目录下，所以我们得给我们自己的环境安装一个easy_install。
下载
wget http://peak.telecommunity.com/dist/ez_setup.py
~/python-lib/bin/python&#160;ez_setup.py
Downloading&#160;http://cheeseshop.python.org/packages/2.4/s/setuptools/setuptools-0.6c3-py2.4.egg
Processing&#160;setuptools-0.6c3-py2.4.egg
creating /home/gavin/python-lib/lib/python2.4/site-packages/setuptools-0.6c3-py2.4.egg
Extracting&#160;setuptools-0.6c3-py2.4.egg to
/home/gavin/python-lib/lib/python2.4/site-packages
Adding&#160;setuptools 0.6c3 to easy-install.pth file
Installing&#160;easy_install script to /home/gavin/python-lib/bin
Installing&#160;easy_install-2.4 script to /home/gavin/python-lib/bin
&#160;
Installed /home/gavin/python-lib/lib/python2.4/site-packages/setuptools-0.6c3-py2.4.egg
Processing&#160;dependencies for [...]]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/%e8%ae%a9easy_install%e6%9e%84%e9%80%a0%e8%87%aa%e5%b7%b1%e7%9a%84py-thon%e5%b0%8f%e5%a4%a9%e5%9c%b0.html/feed</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>shell下调试Django的方便小toolkit</title>
		<link>http://hackgou.itbbq.com/%e4%b8%8b%e8%b0%83%e8%af%95django%e7%9a%84%e6%96%b9%e4%be%bf%e5%b0%8ftoolkit.html</link>
		<comments>http://hackgou.itbbq.com/%e4%b8%8b%e8%b0%83%e8%af%95django%e7%9a%84%e6%96%b9%e4%be%bf%e5%b0%8ftoolkit.html#comments</comments>
		<pubDate>Mon, 09 Oct 2006 08:57:01 +0000</pubDate>
		<dc:creator>HackGou</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Python_Zoplone]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/%e4%b8%8b%e8%b0%83%e8%af%95django%e7%9a%84%e6%96%b9%e4%be%bf%e5%b0%8ftoolkit/</guid>
		<description><![CDATA[在调试的时候，有时候shell下面是很方便的。 除了manage.py shell之外，下面这几行代码可以帮我们不少忙。
#shell.py 
import&#160;os&#160;
import&#160;sys&#160;
os.environ['DJANGO_SETTINGS_MODULE'] = &#34;app.settings&#34;&#160;
sys.path.append(os.getcwd())&#160; &#160; #shell.py 和其他module的路径有可能要修改 
from&#160;app.mymod.models import mymod
这样 就可以调试mymod了！比较方便！ :D 其实说白了就是那个&#8217;DJANGO_SETTINGS_MODULE&#8217;环境变量没有设置，设置了之后就好了！ 后面的from app.mymod.models import mymod是为了方便，免得每次调试都输入这些import。
]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/%e4%b8%8b%e8%b0%83%e8%af%95django%e7%9a%84%e6%96%b9%e4%be%bf%e5%b0%8ftoolkit.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用函数调用来默认值填充models中字段的默认值</title>
		<link>http://hackgou.itbbq.com/%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e6%9d%a5%e9%bb%98%e8%ae%a4%e5%80%bc%e5%a1%ab%e5%85%85models%e4%b8%ad%e5%ad%97%e6%ae%b5%e7%9a%84%e9%bb%98%e8%ae%a4%e5%80%bc.html</link>
		<comments>http://hackgou.itbbq.com/%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e6%9d%a5%e9%bb%98%e8%ae%a4%e5%80%bc%e5%a1%ab%e5%85%85models%e4%b8%ad%e5%ad%97%e6%ae%b5%e7%9a%84%e9%bb%98%e8%ae%a4%e5%80%bc.html#comments</comments>
		<pubDate>Thu, 06 Jul 2006 10:33:00 +0000</pubDate>
		<dc:creator>blog</dc:creator>
				<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e6%9d%a5%e9%bb%98%e8%ae%a4%e5%80%bc%e5%a1%ab%e5%85%85models%e4%b8%ad%e5%ad%97%e6%ae%b5%e7%9a%84%e9%bb%98%e8%ae%a4%e5%80%bc/</guid>
		<description><![CDATA[ 使用函数调用来默认值填充models中字段的默认值，比如使用  datetime.datetime.now来填充 字段类型为日期型的时候最为有用，当然不只可以用于日期型字段。扩展一下，完  全可以使 用自定义的方法来填充默认值

     Model source code
from django.db import models from datetime import datetime
class Article(models.Model):     headline = models.CharField(maxlength=100, default=&#8217;Default headline&#8217;)     pub_date = models.DateTimeField(default=datetime.now)
    def __str__(self):         return self.headline 
]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e6%9d%a5%e9%bb%98%e8%ae%a4%e5%80%bc%e5%a1%ab%e5%85%85models%e4%b8%ad%e5%ad%97%e6%ae%b5%e7%9a%84%e9%bb%98%e8%ae%a4%e5%80%bc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django中这样翻页，一个字，简单</title>
		<link>http://hackgou.itbbq.com/django%e4%b8%ad%e8%bf%99%e6%a0%b7%e7%bf%bb%e9%a1%b5%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%ad%97%ef%bc%8c%e7%ae%80%e5%8d%95.html</link>
		<comments>http://hackgou.itbbq.com/django%e4%b8%ad%e8%bf%99%e6%a0%b7%e7%bf%bb%e9%a1%b5%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%ad%97%ef%bc%8c%e7%ae%80%e5%8d%95.html#comments</comments>
		<pubDate>Thu, 06 Jul 2006 10:30:01 +0000</pubDate>
		<dc:creator>blog</dc:creator>
				<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/django%e4%b8%ad%e8%bf%99%e6%a0%b7%e7%bf%bb%e9%a1%b5%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%ad%97%ef%bc%8c%e7%ae%80%e5%8d%95/</guid>
		<description><![CDATA[  29. Object pagination
Django provides a framework for paginating a list of objects in a few  lines of code. This is often useful for dividing search results or long  lists of objects into easily readable pages.
     Model source code
from django.db import models
class Article(models.Model):     headline [...]]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/django%e4%b8%ad%e8%bf%99%e6%a0%b7%e7%bf%bb%e9%a1%b5%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%ad%97%ef%bc%8c%e7%ae%80%e5%8d%95.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>保存/删除前后的额外动作</title>
		<link>http://hackgou.itbbq.com/%e4%bf%9d%e5%ad%98%e5%88%a0%e9%99%a4%e5%89%8d%e5%90%8e%e7%9a%84%e9%a2%9d%e5%a4%96%e5%8a%a8%e4%bd%9c.html</link>
		<comments>http://hackgou.itbbq.com/%e4%bf%9d%e5%ad%98%e5%88%a0%e9%99%a4%e5%89%8d%e5%90%8e%e7%9a%84%e9%a2%9d%e5%a4%96%e5%8a%a8%e4%bd%9c.html#comments</comments>
		<pubDate>Wed, 05 Jul 2006 14:48:00 +0000</pubDate>
		<dc:creator>HackGou</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/%e4%bf%9d%e5%ad%98%e5%88%a0%e9%99%a4%e5%89%8d%e5%90%8e%e7%9a%84%e9%a2%9d%e5%a4%96%e5%8a%a8%e4%bd%9c/</guid>
		<description><![CDATA[在Django中，常常会出现这样的情况： 在保存一个对象到数据库中或者从数据库把该对象删除的时候，希望可以执行另外一些附加的操作，
比如：
class Place(models.Model):
        name = models.CharField(maxlength=50)
        address = models.CharField(maxlength=80)
        def&#160;save (self):
              self.name = 'hackgou'
              print&#160;&#34;Before save&#34;
              super(Place, self).save()&#160;#call the 'real' save() method
              print&#160;&#34;After save&#34;
        def&#160;delete (self): 
              self.name = &#34;test&#34;
              super(Place,self).save()&#160;#这是在删除么 :P
        def&#160;__str__(self): 
              return&#160;&#34;%s the place&#34; % self.name
&#62;&#62;from&#160;djangoTest.oneToOne.models import *
&#62;&#62;&#62;l = Place(None,&#34;Gavin&#34;,&#34;sichuang&#34;)
&#62;&#62;&#62;l
&#62;&#62;&#62;l.save()
Before
save
After&#160;save
&#62;&#62;&#62; l.name
'hackgou'
&#62;&#62;&#62; l = Place.objects.get(name__startswith=&#34;QQ&#34;)
&#62;&#62;&#62;l
&#62;&#62;&#62; l.delete()
&#62;&#62;&#62; l.name
'test'
&#62;&#62;&#62;
这好像在玩魔术。
其实这和以前版本中的_save()以及meta中定义_save()来重载Model
的save()一样，只是现在名字和Model中的一样，更加像真正的重载了！
]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/%e4%bf%9d%e5%ad%98%e5%88%a0%e9%99%a4%e5%89%8d%e5%90%8e%e7%9a%84%e9%a2%9d%e5%a4%96%e5%8a%a8%e4%bd%9c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fastCGI方式跑Django</title>
		<link>http://hackgou.itbbq.com/fastcgi%e6%96%b9%e5%bc%8f%e8%b7%91django.html</link>
		<comments>http://hackgou.itbbq.com/fastcgi%e6%96%b9%e5%bc%8f%e8%b7%91django.html#comments</comments>
		<pubDate>Wed, 07 Jun 2006 17:08:15 +0000</pubDate>
		<dc:creator>HackGou</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://hackgou.itbbq.com/fastcgi%e6%96%b9%e5%bc%8f%e8%b7%91django/</guid>
		<description><![CDATA[原本想找个支持mod_python的空间来玩玩，但是要么太贵要么速度太慢，终究还是选择了dreamhost，在他上面买了支持python的空间，打算好好玩玩python这个东东，之前看了看上面的环境：
hackgou@runts:~$whereis python 
python: /usr/bin/python /usr/bin/python2.3 /usr/bin/python2.2-popy-config \
/usr/bin/python2.2 /usr/bin/python2.4 /etc/python2.3 /etc\
/python2.4 /etc/python2.2 /usr/lib/python2.3 /usr/lib/python2.2 \
/usr/lib/python2.4 /usr/local/lib/python2.3 /usr/local/lib/python2.\
2 /usr/local/lib/python2.4 /usr/include/python2.3 /usr/include/python2.2 \
/usr/include/python2.4 /usr/share/man/man1/python.1.gz  
呵呵，够夸张的，从2.2到2.4的版本都有。
还好！fastCGI的支持是知道的，上面的主机对python和perl的支持都是通过FastCGI的方式实现的。以前没有彻底的玩过FastCGI、更别说python的FastCGI了。首先是添加一个Python的FastCGI gateway。虽然dreamhost的wiki上面说使用fcgi.py比较方便，但是后来发现Flup，这也是一个Frame
不光有fastCGI gateway，而且他提供一个类似mod_python的publish的东东，那就用他了：
wget http://www.saddi.com/software/flup/dist/flup-r1968.tar.gz
wget抓来之后。用setup.py安装。/usr/lib/python2.4 咱是没有权限，那就在~/下面建立一个自己的lib-python,作为自己的$PYTHONPATH。
在.bash_prifile里面添加export $PYTHONPATH=$PYTHONPATH:~/lib-python 
OK，开始安装我们自己的lib：
python2.4 setup.py install --install-lib&#160; ~/lib-python/ --install-scripts ~/lib-python/
这样会安装到我自己的lib-python而不是默认的/usr/lib/python2.4/site-packages/。
OK，写个简单的helloworld.py（flup的fcig路径是from flup.server.fcgi import WSGIServer），测试一下flup。OK。通过
然后svn把django的代码也拉到lib-python中去。再按照django的手册创建一个demo，写一个简单的测试app.py。页面是出来了，但是是django报错的东东。还好，聊胜于无。为什么呢？东翻翻、西翻翻，看到木头的文章，他说rewrite后能够成功，但是我还悄悄的去http://www.djangocn.org/django.fcgi看了看，呵呵和我的错误一样。不可能跟这个rewrite有关系的吧，既然如此，那我就添加重写规则吧，一添加，呵呵，果然奏效。
It worked!
页面出来了，不知道为什么rewrite和这个有啥关系，迷糊
 update: 
  如果希望避免export $PYTHONPATH=$PYTHONPATH:~/lib-python 而且也不想添加一堆的path.append()，可以参考：
让easy_install构造自己的py thon小天地 
]]></description>
		<wfw:commentRss>http://hackgou.itbbq.com/fastcgi%e6%96%b9%e5%bc%8f%e8%b7%91django.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
