CherryPy 配置

2023-12-30 23:06 更新

CherryPy自帶Web(HTTP)服務(wù)器。 這就是為什么CherryPy是自包含的,允許用戶在獲取庫的幾分鐘內(nèi)運行CherryPy應(yīng)用程序。

web server充當(dāng)應(yīng)用程序的網(wǎng)關(guān),在此幫助下,所有請求和響應(yīng)都保持跟蹤。

要啟動Web服務(wù)器,用戶必須進行以下調(diào)用 -

cherryPy.server.quickstart()

internal engine of CherryPy的internal engine of CherryPy負責(zé)以下活動 -

  • 創(chuàng)建和管理請求和響應(yīng)對象。
  • 控制和管理CherryPy流程。

該框架帶有自己的配置系統(tǒng),允許您參數(shù)化HTTP服務(wù)器。 配置的設(shè)置可以存儲在語法接近INI格式的文本文件中,也可以存儲為完整的Python字典。

要配置CherryPy服務(wù)器實例,開發(fā)人員需要使用設(shè)置的全局部分。

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"


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號