Python 微型 Web 框架 CherryPy

教程说明:

CherryPy是一个基于Python的面向对象的HTTP框架。使用CherryPy来开发Web Application是非常轻松的。但CherryPy并没用提供一种类似于PHP的templating语言机制。

主要特性:

  • 可靠、兼容 HTTP/1.1、WSGI 线程池

  • 可轻松同时在一台机器上创建多个服务

  • 强大的配置系统

  • 灵活的插件系统

  • 内建缓存管理、会话管理、认证、静态文件支持等等诸多功能

  • 完全可定制

  • 内建分析、测试和覆盖率工具

  • 支持 Python 2.7+, 3.1+, PyPy, Jython 和 Android.

示例代码:

import cherrypy
    
class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True

cherrypy.quickstart(HelloWorld())


温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

CherryPy 一个工作应用程序

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }