
- TurboGears 教程
- TurboGears - 首頁
- TurboGears - 概述
- TurboGears - 環境
- TurboGears - 第一個程式
- TurboGears - 依賴項
- TurboGears - 服務模板
- TurboGears - HTTP 方法
- Genshi 模板語言
- TurboGears - 包含
- TurboGears - JSON 渲染
- TurboGears - URL 層次結構
- TurboGears - Toscawidgets 表單
- TurboGears - 驗證
- TurboGears - 閃現訊息
- TurboGears - Cookie 和會話
- TurboGears - 快取
- TurboGears - SQLAlchemy
- TurboGears - 建立模型
- TurboGears - CRUD 操作
- TurboGears - 資料網格
- TurboGears - 分頁
- TurboGears - 管理員訪問
- 授權與身份驗證
- TurboGears - 使用 MongoDB
- TurboGears - 腳手架
- TurboGears - 鉤子
- TurboGears - 編寫擴充套件
- TurboGears - 可插拔應用程式
- TurboGears - RESTful 應用程式
- TurboGears - 部署
- TurboGears 有用資源
- TurboGears - 快速指南
- TurboGears - 有用資源
- TurboGears - 討論
TurboGears - 部署
要從開發環境切換到成熟的生產環境,應用程式需要部署在真實的Web伺服器上。根據您的實際情況,有多種可用的選項來部署 TurboGears Web 應用程式。
Apache 與 mod_wsgi
mod_wsgi 是由 Graham Dumpleton 開發的 Apache 模組。它允許使用 Apache Web 伺服器服務 WSGI 程式。
首先,如果尚未安裝,請為您的平臺安裝 Apache 2.X。安裝 Apache 後,安裝 mod_wsgi。在伺服器上建立並激活 Python 虛擬環境,並在其中安裝 TurboGears。
在應用程式目錄中安裝您的應用程式,然後建立一個名為 **app.wsgi** 的指令碼。
如下配置 Apache 安裝 -
<VirtualHost *:80> ServerName www.site1.com WSGIProcessGroup www.site1.com WSGIDaemonProcess www.site1.com user = <username> group = www-data threads = 4 python-path = <pythonpath> WSGIScriptAlias myapp/app.wsgi #Serve static files directly without TurboGears Alias /images Alias /css Alias /js CustomLog ErrorLog </VirtualHost>
重啟 Apache
在瀏覽器中輸入 **http://www.site1.com/** 以訪問應用程式。
Circus 和 Chaussette 下的 TurboGears
Circus 是一個程序和套接字管理器。它可用於監控和控制程序和套接字。當與 Chaussette WSGI 伺服器配對時,它可以成為部署應用程式和管理應用程式所需任何相關程序的強大工具。
TurboGears - Google App Engine
從以下網址安裝適用於 Python 的 Google App Engine SDK - https://cloud.google.coms
在您的系統上安裝 Google App Engine。然後開啟 Google Developers Console 並使用您的 Google 帳戶登入 - https://console.developers.google.com/start
建立一個名為 **mytgapp** 的新專案 -

使用 Google App Engine Launcher 建立一個名為 **mytgapp** 的新應用程式。


以下檔案將在指定的目錄中建立 -
- app.yaml
- favicon.ico
- index.yaml
- main.py
預設情況下,建立的應用程式依賴於 Webapp2 框架。要刪除此依賴項,請編輯 app.yaml 檔案並刪除以下部分 -
libraries: - name: webapp2 version: "2.5.2"
在名為 mytgapp 的目錄中建立一個臨時的虛擬環境,並安裝 TurboGears。在其中建立一個 TurboGears 應用程式。現在我們可以繼續編輯由 App Engine 啟動以執行我們的應用程式的 **main.py** 檔案,並在其中實際編寫一個 TurboGears 應用程式。
在 **main.py** 中新增以下內容 -
import os import site site.addsitedir(os.path.join(os.path.dirname(__file__), 'packages')) from tg import expose, TGController, AppConfig class RootController(TGController): @expose() def index(self): return "<h1>Hello World</h1>" config = AppConfig(minimal = True, root_controller = RootController()) app = config.make_wsgi_app()
現在從 App Engine Launcher 執行應用程式,然後單擊“瀏覽”按鈕以檢視該應用程式在本地主機上是否正常執行。
我們已經在開發者控制檯中建立了一個名為 mytgapp 的專案。現在單擊啟動器中的“部署”按鈕。部署過程結束後,訪問 **http://mytgapp.appspot.com/** 以檢視我們的線上應用程式。
