首先安裝好wsgi模塊並啓用: 1.下載地址:我本機是python2.7 http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py27-3.3.so 2.把mod_wsgi-win32-ap22py27-3.3.so放到apache安裝目錄下的modules目錄下 3.打開 http.conf 添加:LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.sohtml
下載安裝web.py模塊:python
easy_install -U web.pyweb
或者手動下載安裝:apache
1.下載地址: http://webpy.org 2.解壓到任意目錄,進入目錄python setup.py install,安裝完畢後打開idle編輯器測試是否安裝成功:瀏覽器
1
2
3
4
5
6
7
8
|
>>>
import
web
>>> urls
=
(
'/'
,
'index'
)
>>> app
=
web.application(urls,
globals
())
>>>
class
index:
def
GET(
self
):
return
'hello world!'
>>> app.run()
|
在瀏覽器中瀏覽127.0.0.1:8080,查看是否能正常顯示app
開始設置python2.7
好比我之後想把試用web.py的程序都放在d:\develop\webapp目錄下,而且訪問鏈接爲:127.0.0.1/webapp 配置以下:webapp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
LoadModule wsgi_module modules
/
mod_wsgi.so
WSGIScriptAlias
/
webapp
"D:/develop/webapp/index.py/"
Alias
/
webapp
/
static
"D:/develop/webapp/static/"
AddType text
/
html .py
<Directory
"D:/develop/webapp/"
>
AllowOverride
all
Options Indexes FollowSymLinks ExecCGI
Order allow,deny
SetHandler wsgi
-
script
Allow
from
all
<
/
Directory>
|
重啓apache。編輯器
測試是否成功:ide
編輯:d:/develop/webapp/index.py文件:
1
2
3
4
5
6
7
8
9
|
import
web
urls
=
(
'/'
,
'index'
)
class
index:
def
GET(
self
):
return
"hello world!"
app
=
web.application(urls,
globals
(), autoreload
=
False
)
application
=
app.wsgifunc()
|
訪問http://localhost/webapp, 配置完畢。