- 论坛徽章:
- 0
|
原文地址:http://hi.baidu.com/smallfish_xy/blog/item/f5c444fbcef1ebd7b58f3119.html
看到有人在坛子里询问在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'
return render.index(name)
app = web.application(urls, globals())
main = app.cgirun() # 这行是发布到GAE的关键
# templates/index.html
$def with (name)
<b>hello, $name. test by web.py</b>
3. 发布到GAE,测试
e:\googleapp>appcfg.py update pynotes/
到这里,一个简单web.py应用就完成了,然后刷新。GAE显示500 Error!看后台GAE Log显示错误信息:”No module named templates“,去web.py官方溜达了一圈,发现在其cookbook里有一篇文档《How to use templates on Google App Engine》,里面说的很明白啦。因为web.py的模板在GAE上文件系统会有所限制,所有本地得compile一下,具体命令是:python web/template.py --compile templates 最后一个参数是本地对应模板目录templates,如果有多个模板目录则一次运行一次。运行完会在templates会生成一个__init__.py,里面内容有兴趣可以看看,很眼熟的哦。
4. 再次发布到GAE,可以看到OK拉!
[ 本帖最后由 smallfish_xy 于 2009-8-5 16:11 编辑 ] |
评分
-
查看全部评分
|