<?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>smallfish logs &#187; GAE</title>
	<atom:link href="http://chenxiaoyu.org/blog/archives/tag/gae/feed" rel="self" type="application/rss+xml" />
	<link>http://chenxiaoyu.org</link>
	<description>关注 Python &#38; Go &#38; PostgreSQL</description>
	<lastBuildDate>Sat, 07 Aug 2010 10:31:22 +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>Google App Engine 上试用 web.py 笔记</title>
		<link>http://chenxiaoyu.org/blog/archives/18</link>
		<comments>http://chenxiaoyu.org/blog/archives/18#comments</comments>
		<pubDate>Tue, 10 Nov 2009 07:02:36 +0000</pubDate>
		<dc:creator>smallfish</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://pythonchina.org/smallfish/?p=18</guid>
		<description><![CDATA[看到有人在坛子里询问在GAE如何发布web.py有关问题，就尝试了一把。具体安装和使用过程如下，请对照自己本地路径相应修改：
1. 复制本地对应web.py目录到GAE对应应用目录
比如：D:\Python25\Lib\site-packages\web 到 e:\googleapp\pynotes
2. 写测试代码
app.yaml
application: pynotes
version: 1
runtime: python
api_version: 1

handlers:
-  url: /.*
   script: home.py
home.py
import web
render = web.template.render('templates/')
urls = (
    '/', 'index'
)
class index:
    def GET(self):
        web.header('Content-type', 'text/html')
        name = 'smallfish'
     [...]]]></description>
			<content:encoded><![CDATA[<p>看到有人在坛子里询问在GAE如何发布web.py有关问题，就尝试了一把。具体安装和使用过程如下，请对照自己本地路径相应修改：</p>
<p>1. 复制本地对应web.py目录到GAE对应应用目录</p>
<p>比如：D:\Python25\Lib\site-packages\web 到 e:\googleapp\pynotes</p>
<p>2. 写测试代码<br />
app.yaml</p>
<pre lan="yaml">application: pynotes
version: 1
runtime: python
api_version: 1

handlers:
-  url: /.*
   script: home.py</pre>
<p>home.py</p>
<pre lan="Python">import web
render = web.template.render('templates/')
urls = (
    '/', 'index'
)
class index:
    def GET(self):
        web.header('Content-type', 'text/html')
        name = 'smallfish'
        return render.index(name)
app = web.application(urls, globals())
main = app.cgirun() # 这行是发布到GAE的关键</pre>
<p>templates/index.html</p>
<pre lan="html">$def with (name)
<strong>hello, $name. test by web.py</strong></pre>
<p>3. 发布到GAE，测试</p>
<p>e:\googleapp>appcfg.py update pynotes/</p>
<p>到这里，一个简单web.py应用就完成了，然后刷新。GAE显示500 Error！</p>
<p>看后台GAE Log显示错误信息：”No module named templates“，去web.py官方溜达了一圈，发现在其cookbook里有一篇文档《<a href="http://webpy.org/cookbook/templates_on_gae" target="_blank">How to use templates on Google App Engine</a>》，里面说的很明白啦。</p>
<p>因为web.py的模板在GAE上文件系统会有所限制，所有本地得compile一下，具体命令是：<strong>python web/template.py &#8211;compile templates</strong> 最后一个参数是本地对应模板目录templates，如果有多个模板目录则一次运行一次。运行完会在templates会生成一个__init__.py，里面内容有兴趣可以看看，很眼熟的哦。</p>
<p>4. 再次发布到GAE，可以看到OK拉！</p>
<hr />
<p><small>© smallfish for <a href="http://chenxiaoyu.org">smallfish logs</a>, 2009. |
<a href="http://chenxiaoyu.org/blog/archives/18">Permalink</a> |
<a href="http://chenxiaoyu.org/blog/archives/18#comments">4 comments</a> |
Add to
<a href="http://del.icio.us/post?url=http://chenxiaoyu.org/blog/archives/18&title=Google App Engine 上试用 web.py 笔记">del.icio.us</a>
<br/>
Post tags: <a href="http://chenxiaoyu.org/blog/archives/tag/gae" rel="tag">GAE</a>, <a href="http://chenxiaoyu.org/blog/archives/tag/python" rel="tag">Python</a><br/>
</small></p>
<p>
<script type="text/javascript"><!--
google_ad_client = "pub-8914011260472945";
/* 468x60, 创建于 09-11-19 */
google_ad_slot = "7198645178";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</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://chenxiaoyu.org/blog/archives/18/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
