Example: Develop Web application on Baidu App Engine using CherryPy
2014-07-22 21:48
267 查看
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:
The key here is that url property should be /* rather than /. And notice index.py is the entrance of your application.
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.
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.相关文章推荐
- Web.py Cookbook 简体中文版 - How to use templates on Google App Engine
- Simple Web Application using Cherrypy in Python 3.3 with MySQL
- 在GAE(Google App Engine)上搭建python2.7的web.py程序
- Spring 3 MVC Framework Based Hello World Web Application Example Using Maven, Eclipse IDE And Tomcat
- Using Struts to Develop Our Web Application
- Step-by-Step:Installation and Configuration of a secure web application using MySQL,OpenSA Web Server, Tomcat and OpenSSL,on a N
- Search Engine Optimization for Flash: Best practices for using Flash on the web
- Installing and Running Google App Engine on a Linux System: Appendix D - Using Google App Engine
- Spring webapp - shutting down threads on Application stop
- web.py 0.3 新手指南 - RESTful doctesting using app.request
- google appengine 上试用 web.py 笔记
- CherryPy Essentials: Rapid Python Web Application Development
- Restful application based on Cherrypy
- Servlet:"action" failed to preload on startup in web application 问题的解决
- Using OpenLayers to develop a WebGIS Client
- Unable to start debugging on the web server. You do not have permission to debug the application. The URL for this project is in
- Trace Application Engine Processes Using Process Definitions
- Trace Application Engine Processes Using Process Definitions
- Using .Net, Flex, and Red5 to create a flash web application
- If you have multiple web application run how to determin which is yours when you debug using visual studio 2008?