In the past few months, I has developed and simple applications on Baidu App Engine. Compared to Google apps Engine, or Nitrous.io, the documentation of BAE is really not good enough. The only advantage of BAE are stable-you needn ' t to worry on gfw-on Mainland China. I ' m used to CherryPy to does 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
Modify it work, it's like this:
handlers: -URL:/* script:index.py -expire:. jpg Modify years -expire:. swf modify Ten ye Ars -expire:. png modify years -expire:. gif Modify years-expire:. JPG Modify years -expire:. ico Modify Years
The key is this URL property should be/* rather than/. And notice index.py is the entrance of your application.
index.py
basiclly, this file would look like this:
# -*-coding:utf-8-*- import CherryPy import script try : from bae.core.wsgi 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 ' was just a file I created to handle the actual logic. The key is wsgiapplication which are offered by BAE, and we should wrap our apps created by CherryPy framework with it. Using Try ... except structure here, we can use the same code both on the BAE and on local environment, which makes debugging more Convenient.
3. Problem Remain:session
It seems that the session function would not work very well on BAE, I ' ve tried different configurations but can ' t make it. Next time I'll go into it and try to figure out the reason.