首页 > 移动平台 > 详细

Example: Develop Web application on Baidu App Engine using CherryPy

时间:2014-07-23 02:36:57      阅读:446      评论:0      收藏:0      [点我收藏+]

In the past few months, I have developed two simple applications on Baidu App Engine. Compared to Google App Engine, or Nitrous.Io, the documentation of BAE is really not good enough. The only advantage of BAE is stable - you needn‘t to worry about GFW - on Mainland China. I‘m used to CherryPy to do simple web applications, and after some attempts, I figure out how to deploy it to BAE:

1. Create a deployment on BAE

Remember to select the type as python-web. 

2. Checkout and modify code

When done, notice these files:

requirements.txt

As the documentation says, this is where we declare the library dependencies we want. So we just write:

cherrypy

app.conf

Here to let it work, modify it like this:

handlers:
  - url : /*
    script: index.py

  - expire : .jpg modify 10 years
  - expire : .swf modify 10 years
  - expire : .png modify 10 years
  - expire : .gif modify 10 years
  - expire : .JPG modify 10 years
  - expire : .ico modify 10 years

The key here is that url property should be /* rather than /. And notice index.py is the entrance of your application. 

index.py

Basiclly, this file will look like this:

#-*- coding:utf-8 -*-
import cherrypy
import script

try:
    from bae.core.wsgi import WSGIApplication
    app = cherrypy.tree.mount(script.HelloWorld(environment), "/", config=script.CONFIG)
    application = WSGIApplication(app)
except ImportError:
    cherrypy.quickstart(script.HelloWorld(environment), config=script.CONFIG)

Here the ‘script.py‘ is just a file I created to handle the actual logic. The key here is WSGIApplication which is offered by BAE, and we should wrap our app created by CherryPy framework with it. Using try... except structure here, we can use same code both on BAE and on local environment, which makes debugging more convenient. 

3. Problem remain: Session

It seems that the session function will not work very well on BAE, I‘ve tried different configurations but can‘t make it. Next time I will go into it and try to figure out the reason.

Example: Develop Web application on Baidu App Engine using CherryPy,布布扣,bubuko.com

Example: Develop Web application on Baidu App Engine using CherryPy

原文:http://www.cnblogs.com/toowhite/p/3861484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!