小试appengine
首先是一些运行环境的准备工作
python主页 下载一份最新的python
appengine主页 下载sdk(体积很小,才1m多)
然后,登陆google帐户申请开通使用权限,发条短信而已也很简单,注册一个appspot的二级域名,之后所编写的应用就可以直接上传到这个域名所在的本地目录(一经申请就不能编辑了,但一个帐户可以申请3个)
在d盘新建一个名为liangapp的目录,新增名为app.yaml的配置文件,有点类似rails 。内容如下
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
然后新建配置文件里对应的liangapp.py文件
1
import wsgiref.handlers
2
from google.appengine.api import users
3
from google.appengine.ext import webapp
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
class Main:
6
def get(webapp.RequestHandler):
7
user = users.get_current_user();
8
if user:
9
self.response.headers['Content-Type'] = 'text/plain'
10
self.response.out.write('hello: ' + user.nickname());
11
else:
12
self.redirect(users.create_login_url(self.request.uri))
13![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
def main():
15
app = webapp.WSGIApplication([('/', Main)], debug=True)
16
webapp.util.run_wsgi_app(app)
17![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
if __name__ == '__main__'
19
main()
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
功能很简单,一目了然。 就是判断当前访问的用户是否已登录google帐户,是的话显示账户名,否则转向登陆页
测试一下看刚写的代码是否能正常工作。打开命令行 输入 dev_appserver.py liangapp --port=8888,成功的话打开ie,输入http://localhost:8888/就可以看到效果了
上传到刚才申请的域名liangapp.appspot.com也很简单, 同样是命令行 appcfg.py liangapp ,输入用户密码就可以了。
posted on 2008-06-27 20:42 yyliuliang 阅读(286) 评论(0) 编辑 收藏 举报