codecamp

CherryPy 配置

CherryPy自带Web(HTTP)服务器。 这就是为什么CherryPy是自包含的,允许用户在获取库的几分钟内运行CherryPy应用程序。

web server充当应用程序的网关,在此帮助下,所有请求和响应都保持跟踪。

要启动Web服务器,用户必须进行以下调用 -

cherryPy.server.quickstart()

internal engine of CherryPy的internal engine of CherryPy负责以下活动 -

  • 创建和管理请求和响应对象。
  • 控制和管理CherryPy流程。

该框架带有自己的配置系统,允许您参数化HTTP服务器。 配置的设置可以存储在语法接近INI格式的文本文件中,也可以存储为完整的Python字典。

要配置CherryPy服务器实例,开发人员需要使用设置的全局部分。

global_conf = {
   'global': {
      'server.socket_host': 'localhost',
      'server.socket_port': 8080,
   },
}
application_conf = {
   '/style.css': {
      'tools.staticfile.on': True,
      'tools.staticfile.filename': os.path.join(_curdir, 'style.css'),
   }
}
This could be represented in a file like this:
[global]
server.socket_host = "localhost"
server.socket_port = 8080
[/style.css]
tools.staticfile.on = True
tools.staticfile.filename = "/full/path/to.style.css"


CherryPy 测试安装
CherryPy HTTP合规性
温馨提示
下载编程狮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; }