读书人

在GAE(Google App Engine)下搭建pytho

发布时间: 2012-08-28 12:37:01 作者: rapoo

在GAE(Google App Engine)上搭建python2.7的web.py程序
资源:
1、下载GAE的sdk for python。https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python
2、下载GAE支持的python版本。python2.5和python2.7
3、下载python的flup模块。【前提保证安装了setuptools,否则不能安装python模块】
4、安装MySQLdb模块。【可选,如果要用到mysql数据库的话】

体验hello world:
1、新建一个helloworld目录,注意是小写
2、其下新建一个helloworld.py文件
3、添加如下内容:

#encoding: utf-8import webrender = web.template.render('templates/', cache=False)urls = ('/(.*)', 'hello')app = web.application(urls, globals())class hello:        def GET(self, name):if not name: name = 'World'return render.index(name)if __name__ == "__main__":app.cgirun()   
5、编译模板文件,原因网上都有。在helloworld主目录下运行如下命令:
python web/template.py --compile templates
6、编译成功后会创建一个__init__.py文件,并且每次模板有改动后需要重新编译
7、重新启动GAE,一切安好便是晴天,呵呵!

上传你应用:
至此,我们的demo文件已经完成了,接下来就是要上传至GAE的真实环境了。上传过程包括如下的步骤:
1、注册一个google帐号并申请一个Application ID
2、修改app.yaml文件中的application内容为你刚申请的Application ID
3、helloworld目录外使用命令行上传你的程序:appcfg.py update helloworld/
4、输入申请Application ID的帐号和密码
5、上传成功你就大功告成啦

参考资料:
http://webpy.org
http://www.189works.com/article-39148-2.html
https://developers.google.com/appengine/docs/python/gettingstartedpython27/

读书人网 >Web前端

热点推荐