<?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>Tairan's Story &#187; python</title>
	<atom:link href="http://www.tairan.net/index.php/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tairan.net</link>
	<description>「知之真切笃实处即是行。行之明觉精察处即是知，知行工夫不可离。」</description>
	<lastBuildDate>Mon, 26 Jul 2010 12:12:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>快速建立HTTP Server共享文件</title>
		<link>http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/</link>
		<comments>http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/#comments</comments>
		<pubDate>Fri, 28 May 2010 00:27:12 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.tairan.net/?p=839</guid>
		<description><![CDATA[From Tairan&#8217;s Story, post 快速建立HTTP Server共享文件 Python内置了一个简单的Web服务器可以用来建立一个HTTP Server来共享某个目录下的文件，尤其是在Unix-Like+windows的混合网络中更是方便快捷。 Server 假设 IP 为 192.168.1.1 首先进入到需要共享的目录，如 cd ~/share/ python -m SimpleHTTPServer 8000 #Python 2.6 OR python -m http.server 8000 #Python 3.0 Client 访问http://192.168.1.1:8000就可以看到Server共享出来的文件了。 From Tairan&#8217;s Story, post 快速建立HTTP Server共享文件 © Daniel Wang for Tairan's Story, 2010. &#124; Permalink &#124; 5 comments &#124; Add to del.icio.us Post tags: [...]]]></description>
			<content:encoded><![CDATA[<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/">快速建立HTTP Server共享文件</a></p>
</div>
<p>Python内置了一个简单的Web服务器可以用来建立一个<em>HTTP Server</em>来共享某个目录下的文件，尤其是在Unix-Like+windows的混合网络中更是方便快捷。</p>
<p><strong>Server</strong><br />
假设 IP 为 192.168.1.1</p>
<p>首先进入到需要共享的目录，如</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python <span style="color: #660033;">-m</span> SimpleHTTPServer <span style="color: #000000;">8000</span> <span style="color: #666666; font-style: italic;">#Python 2.6</span></pre></div></div>

<p><em>OR</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python <span style="color: #660033;">-m</span> http.server <span style="color: #000000;">8000</span> <span style="color: #666666; font-style: italic;">#Python 3.0</span></pre></div></div>

<p><strong>Client</strong><br />
访问http://192.168.1.1:8000就可以看到Server共享出来的文件了。
<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/">快速建立HTTP Server共享文件</a></p>
</div>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan's Story</a>, 2010. |
<a href="http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/#comments">5 comments</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/&title=快速建立HTTP Server共享文件">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/python/" rel="tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2010/05/28/shared-by-simplehttpserver/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t up-to-date</title>
		<link>http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/</link>
		<comments>http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 09:26:07 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Thinking]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://blog.tairan.org/?p=228</guid>
		<description><![CDATA[From Tairan&#8217;s Story, post Don&#8217;t up-to-date 不要最新的！ 貌似很多程序员都喜欢尝新，不停的追赶这语言那技术。此时之前，我也是其中的一份子，而且还比较狂热。这几天遇到的一些事情让我懂得，最新的不一定是最合适的。 说说是什么事情让我停止狂热的追赶最新的东西吧： 现在Python 3.0 已经发布一段时间了，并且大叔告诉我们现在还有很多周边软件没有跟上，所以除非是新项目，还是保守点选择2.6 比较合适。于是乎，就选择2.6.1吧 谁知 安装 trac 以及相关软件的时候，有个装不上，&#62;_&#60; 因为忘记记录存档想不起是哪个软件了，真对不起自己和大家！ 再说说Apache吧，一直都选择2.2.x来玩，搭建SVN服务器等。CollabNet 做的集成包真的很好用，安装也简单！可用这个Apache2.2 安装 MOD_SCGI 却死活启动不了服务，从Google的结果来看，虽然有人提出自己编译MOD_SCGI for Apache 2.2，可也是意淫了一下说：“应该很容易”，&#8211; 谁不知道在Windows 上玩这些成本有多高！ 无奈退而求其次，有换了个Apache2.0.x用用。 盲目的求新会走很多弯路。不过也能获得一些经验！ 兰迪教授说：当得不到想得到的东西时，就得到了经验。 虽说不要最新的，也没说一直守旧不前进，使用开源软件时最好用当前版本的前一个次版本最佳。 一来是软件经过了一段时间的考验，二是周边的软件也都跟上了。不至于走两步退一步。 =========================== Trac + Apache + SCGI 的安装方法比较容易，性能稳定方面自己倒是没有测试过。主要参考了这篇文章 Subversion无痛起步 &#8212; Trac 0.10b1 + Apache 2 From Tairan&#8217;s Story, post Don&#8217;t up-to-date © Daniel [...]]]></description>
			<content:encoded><![CDATA[<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/">Don&#8217;t up-to-date</a></p>
</div>
<p><strong>不要最新的！</strong></p>
<p>貌似很多程序员都喜欢尝新，不停的追赶这语言那技术。此时之前，我也是其中的一份子，而且还比较狂热。这几天遇到的一些事情让我懂得，最新的不一定是最合适的。</p>
<p>说说是什么事情让我停止狂热的追赶最新的东西吧：<br />
现在Python 3.0 已经发布一段时间了，并且大叔告诉我们现在还有很多周边软件没有跟上，所以除非是新项目，还是保守点选择2.6 比较合适。于是乎，就选择2.6.1吧<br />
谁知 安装 trac 以及相关软件的时候，有个装不上，&gt;_&lt; 因为忘记记录存档想不起是哪个软件了，真对不起自己和大家！</p>
<p>再说说Apache吧，一直都选择2.2.x来玩，搭建SVN服务器等。CollabNet 做的集成包真的很好用，安装也简单！可用这个Apache2.2 安装 MOD_SCGI 却死活启动不了服务，从Google的结果来看，虽然有人提出自己编译MOD_SCGI for Apache 2.2，可也是意淫了一下说：“应该很容易”，&#8211; 谁不知道在Windows 上玩这些成本有多高！<br />
无奈退而求其次，有换了个Apache2.0.x用用。</p>
<p><span style="background-color:yellow"><strong>盲目的求新会走很多弯路</strong>。</span>不过也能获得一些经验！ 兰迪教授说：<span style="background-color:yellow">当得不到想得到的东西时，就得到了经验。</span></p>
<p>虽说不要最新的，也没说一直守旧不前进，使用开源软件时最好用当前版本的前一个次版本最佳。 一来是软件经过了一段时间的考验，二是周边的软件也都跟上了。不至于走两步退一步。</p>
<p>===========================<br />
Trac + Apache + SCGI 的安装方法比较容易，性能稳定方面自己倒是没有测试过。主要参考了这篇文章 <a href="http://onezstudio.blogspot.com/2006/09/getting-started-with-subversion-trac.html">Subversion无痛起步 &#8212; Trac 0.10b1 + Apache 2</a>
<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/">Don&#8217;t up-to-date</a></p>
</div>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan's Story</a>, 2009. |
<a href="http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/&title=Don&#8217;t up-to-date">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/apache/" rel="tag">Apache</a>, <a href="http://www.tairan.net/index.php/tag/python/" rel="tag">python</a>, <a href="http://www.tairan.net/index.php/tag/thinking/" rel="tag">Thinking</a>, <a href="http://www.tairan.net/index.php/tag/trac/" rel="tag">trac</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2009/02/13/dont-up-to-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>why webpy is instable?</title>
		<link>http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/</link>
		<comments>http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 15:09:36 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.tairan.org/?p=139</guid>
		<description><![CDATA[From Tairan&#8217;s Story, post why webpy is instable? 有时脑袋有了idea，就想马上实现它。原本PHP是个不错的选择，可是自己以后的工作和规划中已经排除了它，取而代之的是Python。 用Python写一个简单的web application可不是那么容易的事情，以前玩了一段时间的Django，那时还不是1.0 Release版本。好不容易盼到Django 1.0 release了，却发现有很多东西不认识了。怎奈写一个小东东就这么难呢？ 寻寻觅觅，忽见web.py是一个更简洁的framework，so, 看文档，做练习。从下班一直捣鼓到此时22:55，发现web.py这个framework中还是有很多Bug的。 官方释放版本是0.23，在cookbook中写到如何使用subapplication。 blog.py import web urls = &#40; &#34;&#34;, &#34;reblog&#34;, &#34;/(.*)&#34;, &#34;blog&#34; &#41; &#160; class reblog: def GET&#40;self&#41;: raise web.seeother&#40;'/'&#41; &#160; class blog: def GET&#40;self, path&#41;: return &#34;blog &#34; + path &#160; app_blog = web.application&#40;urls, locals&#40;&#41;&#41; 这里有一个bug: AttributeError: 'module' object [...]]]></description>
			<content:encoded><![CDATA[<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/">why webpy is instable?</a></p>
</div>
<p>有时脑袋有了idea，就想马上实现它。原本PHP是个不错的选择，可是自己以后的工作和规划中已经排除了它，取而代之的是Python。</p>
<p>用Python写一个简单的web application可不是那么容易的事情，以前玩了一段时间的Django，那时还不是1.0 Release版本。好不容易盼到Django 1.0 release了，却发现有很多东西不认识了。怎奈写一个小东东就这么难呢？</p>
<p>寻寻觅觅，忽见web.py是一个更简洁的framework，so, 看文档，做练习。从下班一直捣鼓到此时22:55，发现web.py这个framework中还是有很多Bug的。</p>
<p>官方释放版本是0.23，在cookbook中写到如何使用subapplication。<br />
<em>blog.py</em></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> web
urls = <span style="color: black;">&#40;</span>
  <span style="color: #483d8b;">&quot;&quot;</span>, <span style="color: #483d8b;">&quot;reblog&quot;</span>,
  <span style="color: #483d8b;">&quot;/(.*)&quot;</span>, <span style="color: #483d8b;">&quot;blog&quot;</span>
<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> reblog:
    <span style="color: #ff7700;font-weight:bold;">def</span> GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">raise</span> web.<span style="color: black;">seeother</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> blog:
    <span style="color: #ff7700;font-weight:bold;">def</span> GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, path<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;blog &quot;</span> + path
&nbsp;
app_blog = web.<span style="color: black;">application</span><span style="color: black;">&#40;</span>urls, <span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>这里有一个bug:<br />
<code>AttributeError: 'module' object has no attribute 'application'</code><br />
Google以后才知道要用0.3版的才行，因为0.23版中根本就没有application.py这个文件</p>
<p>这个问题解决以后，在code.py中引用subapp</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">urls = <span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">'/blog'</span>, blog.<span style="color: black;">app_blog</span>
<span style="color: black;">&#41;</span></pre></div></div>

<p>又有一个bug:<br />
<code><br />
AttributeError: 'module' object has no attribute 'app_blog'<br />
</code></p>
<p>痛苦阿，明天还要上班！暂时放一下web.py，让我在研究一下Django吧，好歹熟悉一些。如今的Django不仅很美，而且还很强壮，当然也很肥胖(相对)。</p>
<p>开源，路还很长。祝福web.py
<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/">why webpy is instable?</a></p>
</div>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan's Story</a>, 2008. |
<a href="http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/&title=why webpy is instable?">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/python/" rel="tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2008/11/25/why-webpy-is-instable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python中的lambda函数</title>
		<link>http://www.tairan.net/index.php/2008/08/25/lambda-in-python/</link>
		<comments>http://www.tairan.net/index.php/2008/08/25/lambda-in-python/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 23:27:00 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tairan.wordpress.com/2008/08/25/python%e4%b8%ad%e7%9a%84lambda%e5%87%bd%e6%95%b0/</guid>
		<description><![CDATA[From Tairan&#8217;s Story, post Python中的lambda函数 Python支持一种有趣的语法，它允许你快速定义单行的最小函数。这些叫做lambda函数，是从Lisp借鉴来的，可以用在任何需要函数的地方。 总的来说，lambda函数可以接收任意多个参数并且返回单个表达式的值。lambda函数不能包含命令，包含的表达式不能超过一个。不要试图向lambda函数中塞入太多的东西；如果你需要更复杂的东西，应该定义一个普通函数，然后想让它多长就多长。（当然，太长的函数也是不推荐的） lambda函数是一种风格问题。不一定非要使用它们；任意能够使用它们的地方，都可以定义一个单独的普通函数来进行替换。一般将它们用在需要封装的特殊的，非重用代码上，避免令代码中充斥着大量的单行函数。 lambda示例 1 # 普通函数 2 def f(x): 3 &#160;&#160;&#160;&#160; return x*2 4 5 &#62;&#62;&#62;f(3) 6 6 7 8 # lambda函数 9 func = lambda x: x*210 &#62;&#62;&#62;func(3)11 612 &#62;&#62;&#62;(lambda x: x*2)(3)13 6 From Tairan&#8217;s Story, post Python中的lambda函数 © Daniel Wang for Tairan's Story, 2008. &#124; Permalink &#124; [...]]]></description>
			<content:encoded><![CDATA[<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/08/25/lambda-in-python/">Python中的lambda函数</a></p>
</div>
<p>Python支持一种有趣的语法，它允许你快速定义单行的最小函数。这些叫做lambda函数，是从Lisp借鉴来的，可以用在任何需要函数的地方。
<ul>
<li>总的来说，lambda函数可以接收任意多个参数并且返回单个表达式的值。lambda函数不能包含命令，包含的表达式不能超过一个。不要试图向lambda函数中塞入太多的东西；如果你需要更复杂的东西，应该定义一个普通函数，然后想让它多长就多长。（当然，太长的函数也是不推荐的）</li>
<li>lambda函数是一种风格问题。不一定非要使用它们；任意能够使用它们的地方，都可以定义一个单独的普通函数来进行替换。一般将它们用在需要封装的特殊的，非重用代码上，避免令代码中充斥着大量的单行函数。</li>
</ul>
<p>   lambda示例
<div id="uwfq" style="background-color:rgb(51,51,51);color:rgb(255,255,255);"><span style="color:#ffff00;"> 1 </span><span style="color:#87ceeb;"># 普通函数</span><br /><span style="color:#ffff00;"> 2 </span><span style="color:#f0e68c;"><b>def</b></span> <span style="color:#98fb98;">f</span>(x):<br /><span style="color:#ffff00;"> 3 </span>&nbsp;&nbsp;&nbsp;&nbsp;    <span style="color:#f0e68c;"><b>return</b></span> x*<span style="color:#ffa0a0;">2</span><br /><span style="color:#ffff00;"> 4 </span><br /><span style="color:#ffff00;"> 5 </span>&gt;&gt;&gt;f(<span style="color:#ffa0a0;">3</span>)<br /><span style="color:#ffff00;"> 6 </span><span style="color:#ffa0a0;">6</span><br /><span style="color:#ffff00;"> 7 </span><br /><span style="color:#ffff00;"> 8 </span><span style="color:#87ceeb;"># lambda函数</span><br /><span style="color:#ffff00;"> 9 </span>func = <span style="color:#f0e68c;"><b>lambda</b></span> x: x*<span style="color:#ffa0a0;">2</span><br /><span style="color:#ffff00;">10 </span>&gt;&gt;&gt;func(<span style="color:#ffa0a0;">3</span>)<br /><span style="color:#ffff00;">11 </span><span style="color:#ffa0a0;">6</span><br /><span style="color:#ffff00;">12 </span>&gt;&gt;&gt;(<span style="color:#f0e68c;"><b>lambda</b></span> x: x*<span style="color:#ffa0a0;">2</span>)(<span style="color:#ffa0a0;">3</span>)<br /><span style="color:#ffff00;">13 </span><span style="color:#ffa0a0;">6</span></div>
<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/08/25/lambda-in-python/">Python中的lambda函数</a></p>
</div>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan's Story</a>, 2008. |
<a href="http://www.tairan.net/index.php/2008/08/25/lambda-in-python/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2008/08/25/lambda-in-python/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2008/08/25/lambda-in-python/&title=Python中的lambda函数">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/python/" rel="tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2008/08/25/lambda-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The note of learning Django</title>
		<link>http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/</link>
		<comments>http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 07:37:00 +0000</pubDate>
		<dc:creator>Daniel Wang</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[我的声音]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tairan.wordpress.com/2008/07/30/26/</guid>
		<description><![CDATA[From Tairan&#8217;s Story, post The note of learning Django django 学习笔记 使用 apache2.2 + mod_python 部署django 项目 #装载模块LoadModules python_module modules/mod_python.so #声明虚拟主机NameVirtualHost 127.0.0.1:80 #定义虚拟主机&#60;VirtualHost 127.0.0.1:80&#62;&#60;Location /&#62; SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonDebug On PythonPath &#8220;['D:workspace'] + sys.path&#8221;&#60;/Location&#62;&#60;/VirtualHost&#62; SetEnv DJANGO_SETTINGS_MODULE mysite.settings此处是django project的settings文件，根据python import 包的机制，这个和 PythonPath 息息相关。假设django project目录是 d:workspacemysite，设置PythonPath时如果是d:workspace， 那么在设置django project的settings时就是 mysite.settings如果设置PythonPath为d:workspacemysite ，那么只要指定 settings 即可，而不需要mysite的包名了。此处还影响着 settings.py [...]]]></description>
			<content:encoded><![CDATA[<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/">The note of learning Django</a></p>
</div>
<h1>django 学习笔记</h1>
<h2>使用 apache2.2 + mod_python 部署django 项目</h2>
<p>#装载模块<br />LoadModules   python_module       modules/mod_python.so</p>
<p>#声明虚拟主机<br />NameVirtualHost 127.0.0.1:80</p>
<p>#定义虚拟主机<br />&lt;VirtualHost 127.0.0.1:80&gt;<br />&lt;Location /&gt;<br />    SetHandler python-program<br />    PythonHandler django.core.handlers.modpython<br />    SetEnv DJANGO_SETTINGS_MODULE mysite.settings         <br />    PythonDebug On<br />    PythonPath &#8220;['D:workspace'] + sys.path&#8221;<br />&lt;/Location&gt;<br />&lt;/VirtualHost&gt;</p>
<p>SetEnv DJANGO_SETTINGS_MODULE mysite.settings<br />此处是django project的settings文件，根据python import 包的机制，这个和 PythonPath 息息相关。<br />假设django project目录是 d:workspacemysite，设置PythonPath时如果是d:workspace， 那么在设置django project的settings时就是 mysite.settings<br />如果设置PythonPath为d:workspacemysite ，那么只要指定 settings 即可，而不需要mysite的包名了。<br />此处还影响着 settings.py 文件中的 ROOT_URLCONF</p>
<p>#TODO使用虚拟目录部署</p>
<h2>配置 Django project 中的静态资源 css js jpg 等</h2>
<p>通过阅读他人的源码，把这个问题也明白了。传说 Django 不建议在 settings 设置 MEIDA_ROOT 等相关静态文件配置。那么我们在模板中如何使用这些文件呢。如，在模板中我们使用 /media/css/layout.css ，web server怎么样才能知道这个路径在什么地方呢？<br />当然，Django中提供了相应的解决办法:通过url映射。在urls.py中做一下设置<br />urlpatterns += patterns(&#8221;,<br />      (r&#8217;^media/(?P&lt;path&gt;.*)$&#8217;, &#8216;django.views.static.serve&#8217;, {&#8216;document_root&#8217;:'d:/templates/media&#8217;}),<br />)</p>
<p>通过这样的映射，静态的资源的问题就解决了。:)</p>
<h1>Django URL dispatcher</h1>
<p>1. project 级别的 url 调用 app 级别的url</p>
<p>此处要注意的是，project url + app url 才是真正的url，所以写url的正则表达式时，注意^ $两个符号</p>
<p>2. 通过Url传递Get Request参数</p>
<p>如果我们 detail(request, name) 的方法需要一个name参数，那么我们的正则表达式应该这样写 (r&#8217;^detail/P&lt;?name&gt;w+$&#8217;, &#8216;detail&#8217;)</p>
<p>3. 快捷调用 view<br />在appproject.views中有个index方法 在patterns 中第一个参数指定view后，在以后的调用只需指定方法名即可<br />urlpatterns = patterns(&#8216;appproject.views&#8217;,<br />      (r&#8217;^$&#8217;, &#8216;index&#8217;),<br />)
<div style="font-style: italic">
<p><strong>From</strong> <a href="http://www.tairan.net/">Tairan&#8217;s Story</a>, <strong>post</strong> <a href="http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/">The note of learning Django</a></p>
</div>
<hr />
<p><small>© Daniel Wang for <a href="http://www.tairan.net">Tairan's Story</a>, 2008. |
<a href="http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/">Permalink</a> |
<a href="http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/&title=The note of learning Django">del.icio.us</a>
<br/>
Post tags: <a href="http://www.tairan.net/index.php/tag/django/" rel="tag">Django</a>, <a href="http://www.tairan.net/index.php/tag/python/" rel="tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tairan.net/index.php/2008/07/30/the-note-of-learning-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
