在GAE(Google App Engine)上搭建python2.7的web.py程序
2012-08-09 18:28
555 查看
资源:
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、添加如下内容:
5、添加内容如下:
dev_appserver.py helloworld/ #注意安装GAE时要选择添加安装目录到PATH中,否则此处命名无效
7、启动后没有错误的话,会提示你去访问localhost:8080,管理网址为:http://localhost:8080/_ah/admin/datastore
搭建web.py程序:
其实GAE自己也带有一个web程序,webapp,不过web.py的时候比较多。搭建web.py的步骤有如下几步:
1、复制Lib\site-packages\web安装目录到helloworld目录下
2、修改helloworl.py的内容如下:
4、访问http://localhost:8080
使用web.py的模板:
搭建上面内容都没有什么大错,但是使用web.py时肯定是要用到模板的,使用模板包含如下的步骤:
1、在helloworld目录下新建一个templates目录
2、在其下添加一个index.html文件
3、其内容如下:
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/ 如果有ssl认证错误使用这个命令:appcfg.py update
4、输入申请Application ID的帐号和密码
5、上传成功你就大功告成啦!【https://justfreelikewind.appspot.com/】
参考资料:
http://webpy.org http://www.189works.com/article-39148-2.html https://developers.google.com/appengine/docs/python/gettingstartedpython27/
-------------------------------------------------------------上传中遇到的问题分割线---------------------------------------------------------------------------------
1、用的python2.7 在windows上,报了ssl认证错误
【appcfg.py update
这样解决的,不过安全性就低了】
2、输入邮箱和密码时,报set attribute错误
【这是因为我的账号之前搭建google代理时,设置为2步登录验证的,所以这里密码要用动态生成的密码,https://accounts.google.com/IssuedAuthSubTokens#accesscodes这里可以生成】
3、报502认证错误
【这里是因为还在用google代理,去掉代理直接使用上传命令即可】
4、访问地址app地址提示服务器错误
【这里是因为没有加google代理,被墙了,再次使用google代理即可。真WS】
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、添加如下内容:
print 'Content-Type: text/plain' print '' print 'Hello, world! I\'m in GAE'4、再新建一个app.yaml文件
5、添加内容如下:
application: helloworld version: 1 runtime: python27 api_version: 1 threadsafe: no handlers: - url: /.* script: helloworld.py6、启动gae的sdk所带的网络服务,在helloworld目录的父目录中运行如下命令:
dev_appserver.py helloworld/ #注意安装GAE时要选择添加安装目录到PATH中,否则此处命名无效
7、启动后没有错误的话,会提示你去访问localhost:8080,管理网址为:http://localhost:8080/_ah/admin/datastore
搭建web.py程序:
其实GAE自己也带有一个web程序,webapp,不过web.py的时候比较多。搭建web.py的步骤有如下几步:
1、复制Lib\site-packages\web安装目录到helloworld目录下
2、修改helloworl.py的内容如下:
#encoding: utf-8 import web urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals()) class hello: def GET(self, name): if not name: name = 'World' return 'Hello, ' + name + '!' if __name__ == "__main__": app.cgirun() #注意这里不是app.run()3、重新启动GAE的服务
4、访问http://localhost:8080
使用web.py的模板:
搭建上面内容都没有什么大错,但是使用web.py时肯定是要用到模板的,使用模板包含如下的步骤:
1、在helloworld目录下新建一个templates目录
2、在其下添加一个index.html文件
3、其内容如下:
$def with(name) <div><h1>Hello $name</h1></div>4、修改helloworl.py文件如下:
#encoding: utf-8 import web render = 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/ 如果有ssl认证错误使用这个命令:appcfg.py update
--insecurehelloworld/
4、输入申请Application ID的帐号和密码
5、上传成功你就大功告成啦!【https://justfreelikewind.appspot.com/】
参考资料:
http://webpy.org http://www.189works.com/article-39148-2.html https://developers.google.com/appengine/docs/python/gettingstartedpython27/
-------------------------------------------------------------上传中遇到的问题分割线---------------------------------------------------------------------------------
1、用的python2.7 在windows上,报了ssl认证错误
【appcfg.py update
--insecurehelloworld/
这样解决的,不过安全性就低了】
2、输入邮箱和密码时,报set attribute错误
【这是因为我的账号之前搭建google代理时,设置为2步登录验证的,所以这里密码要用动态生成的密码,https://accounts.google.com/IssuedAuthSubTokens#accesscodes这里可以生成】
3、报502认证错误
【这里是因为还在用google代理,去掉代理直接使用上传命令即可】
4、访问地址app地址提示服务器错误
【这里是因为没有加google代理,被墙了,再次使用google代理即可。真WS】
相关文章推荐
- eclipse python + GAE(Google App Engine) 开发环境搭建
- google appengine 上试用 web.py 笔记
- GAE启动错误 GoogleAppEngineLauncher.py", line 42...解决方案
- Google App Engine, Python2.7的UnicodeDecodeError bug
- Web.py Cookbook 简体中文版 - How to use templates on Google App Engine
- Google App Engine正式支持Python 2.7
- webpy+python2.7+linux环境搭建
- Django+Python+GoogleAppEngine+HTML/XHTML+CSS = WEB APP
- Python: Google App Engine (GAE) Paginator Class
- (GAE)Google App Engine入门程序——helloworld
- Python Web app on GAE
- Google App Engine ProtoRPC Python API 概述
- 使用 Eclipse + PyDev 开发 Google App Engine 程序
- 主题:菜鸟玩GAE(Google App Engine)完全指南
- GAE(Google App Engine)部署时候遇到的问题
- 用Python和Google AppEngine开发基于Google架构的应用软件
- 在GAE(google appengine)中应用sitemesh
- Google App Engine DEMO 站点程序开源啦~
- google app engine 开发环境搭建
- (GAE文档翻译)Google App Engine中如何修改你的数据模型