GAE+bottle+jinja2+beaker快速开发demo - Python,GAE - language - ITeye论坛
GAE+bottle+jinja2+beaker快速开发demo - Python,GAE - language - ITeye论坛
:GAE+bottle+jinja2+beaker快速开发demo
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
作者正文
heartsong
等级: 初级会员
heartsong的博客
性别:
文章: 55
积分: 80
来自: 杭州
发表时间:2011-02-25 最后修改:2011-02-25
< > 猎头职位: 北京: 【北京】游戏公司诚邀php开发工程师
相关文章:
在Google App Engine上用zipimport引入新版的Django
Python Django GAE开发 环境搭建篇
混合使用django模板和jinja模板
推荐群组: Scala圈子
更多相关推荐
Python GAE
相对于Django,bottle可以看成是一个非常精巧的python web framework了,只有一个文件就可以使用了。于是想用这个东西在gae做个简单的demo。
1. GAE+bottle
http://pypi.python.org/pypi/bottle
copy那个bottle.py到gae工程的目录里,现在,可以写一个很简短的代码来测试一下:
main.py
from bottle import route, default_app
from google.appengine.ext.webapp.util import run_wsgi_app
@route
def index():
return 'Hello world!'
def main():
'''Remove this when on production '''
bottle.debug(True)
app = default_app()
run_wsgi_app(app)
if __name__ == '__main__':
main()
同时,要修改app.yaml文件:
handlers:
- url: /.*
script: main.py
现在,就可以直接运行GAE,查看结果了!就这么简单!
2. GAE+bottle+beaker
在GAE+bottle的组合中,如果要使用session的话,查询到bottle的原话如下:
How to implement sessions?
There is no build in support for sessions because there is no right way to do it. Depending on requirements and environment you could use beaker middleware with a fitting backend or implement it yourself.
很清楚的告诉我们,如果要使用session的话,可以考虑beaker,从这里下载:
http://pypi.python.org/pypi/Beaker
下载下来后,把里面的一个beaker文件夹,copy到GAE工程目录中,会作为一个package来使用。
在上面的程序修改如下:
main.py
from bottle import route, default_app
from beaker.middleware import SessionMiddleware
from google.appengine.ext.webapp.util import run_wsgi_app
@route('/')
def index():
session = request.environ['beaker.session']
if 'refrush_times' in session:
refrush_times = int(session['refrush_times'])
else:
refrush_times = 0
refrush_times = refrush_times + 1
session['refrush_times'] = refrush_times
return 'Hello world! You have refrush this page for %s times.' % str(refrush_times)
def main():
'''Remove this when on production '''
bottle.debug(True)
app = default_app()
session_opts = {
'session.type': 'ext:google',
'session.cookie_expires': True,
'session.auto': True,
}
app = SessionMiddleware(app, session_opts)
run_wsgi_app(app)
if __name__ == '__main__':
main()
注意,session_opts里的session.type,如果在GAE下使用,一定要选ext:google,这个是我测试了几个选项之后才发现的。如果你有更好的方法,也欢迎告诉我,谢谢。
最新文章
- WCF学习之旅—基于ServiceDebug的异常处理(十七)
- Tomcat7安装配置 for Ubuntu
- UVALive 6577 Binary Tree 二叉树的LRU串
- linux 服务器对拷命令scp
- Qt之自定义信号和槽函数
- OPENGL学习之路(0)--安装
- 推送XML
- java servlet 代码样例 (demo)
- [AngularJS + Webpack] Using Webpack for angularjs
- css 实现文字过长变成省略号(包含单行的and多行的)
- 解决android studio引用远程仓库下载慢(JCenter下载慢)
- c/c++ linux 进程 fork wait函数
- 一致性哈希算法----nginx负载均衡器配置之一
- Python2.7-hashlib
- Windows/Linux获取当前运行程序的绝对路径
- 洛谷乐多赛 yyy loves Maths VI (mode)
- sublime自定义代码段
- bzoj2242: [SDOI2011]计算器 BSGS+exgcd
- Hex棋
- php与js 编码解码交互
热门文章
- IE 兼容性问题
- NET Core 环境搭建和命令行CLI入门
- 通过原生js的ajax或jquery的ajax获取服务器的时间
- 关于map
- android:background=";@drawable/home_tab_bg";
- Uva 3226 Symmetry
- STL--stack/queue的使用方法
- UI常用控件的一些属性
- Data Structure(2)
- POJ 3691 &;amp; HDU 2457 DNA repair (AC自己主动机,DP)