Python web.py 的安裝 (mod_wsgi)


安裝 easy_install

1
2
3
4
5
6
7
8
9
10
1. 下載 http://peak.telecommunity.com/dist/ez_setup.py
2. 命令提示字元檔中輸入 python ez_setup.py
3. 如果一直停留在下載劃面
- 到 http://pypi.python.org/pypi/setuptools
- 下載相應的 setuptools-X.XXXX-pyX.X.egg
(如: setuptools-0.6c11-py2.6.egg)
- 放於同 ez_setup.py 的目錄中
4. 環境變量的 PATH 中加入
- X:\Application\Python;X:\Application\Python\Scripts;

安裝 web.py

1
easy_install web.py

測試用的 main.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import web

urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()

class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'

if __name__ == "__main__":
application.run()

位於同目錄的 .htaccess

1
2
3
4
5
6
7
8
9
10
11
12
13
<IfModule mod_rewrite.c>      
RewriteEngine on
RewriteBase /webpy
RewriteCond %{REQUEST_URI} !^/icons
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^(/.*)+main.py/
RewriteRule ^(.*)$ main.py/$1 [PT]
</IfModule>

<Files main.py>
SetHandler wsgi-script
Options ExecCGI FollowSymLinks
</Files>

最後打開網址: http://localhost/webpy/main.py