Example:develop Web application on Baidu App Engine using CherryPy

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.