首先安装好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.so
下载安装web.py模块:
easy_install -U web.py
或者手动下载安装:
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,查看是否能正常显示
开始设置
比如我以后想把试用web.py的程序都放在d:developwebapp目录下,并且访问连接为:127.0.0.1/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。
测试是否成功:
编辑: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, 配置完毕。