最近正在摸索 Python,雖然之前有下載過 2.6.1 的直譯器來玩,不過只有淺嘗了一下,而且對於 Python Framework 還懵懵懂懂,只知道 Django 的使用率似乎較高,但是更複雜。

因為我學 Python 想從 WebApp 下手,所以勢必要找個更簡單的框架來用,不小心就摸到 web.py - 專為 WebApp 誕生的 Framework…

不過,嘗試之前就已經被 Apache 設定搞死了,原本使用 CentOS 的 Apache 來當 Web Server,mod_python 有載入、CGI 也設定了卻都 run 不起來,索性就安裝 Ubuntu Server Edition 讓 APT 來幫我搞定 XD

apt-get install libapache-mod-python

安裝過程比較值得注意的是 Apache 的設定,主要就是加入讓 Python 直譯的 Handler:


  Options +ExecCGI
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On
  ...
  ...

Python script 要注意的是如果噴出 Not Found 的訊息,可能要寫個 index function:

#!/usr/bin/env python

def index(req):
    req.content_type = 'text/plain'
    req.write("Hello World!")

延伸閱讀: