1.安装web.py,根据官方例子做就可以: http:///install.zh-cn
简单摘录如下: 下载: http:///static/web.py-0.33.tar.gz
安装: python setup.py install
例子代码写完后,运行: python code.py
2.写hello world的例子代码:
这里有一点是要注意,页面直接点进去的链接是 http:///tutorial2 这个文章写出的代码是这个样子的: import web
urls = (
'/', 'index'
)
class index:
def GET(self):
print "Hello, world!"
if __name__ == "__main__": web.run(urls, globals())
运行话会报下面的错误:
D:\dev\www>python code.py
Traceback (most recent call last):
File "code.py", line 8, in <module>
if __name__ == "__main__": web.run(urls, globals())
AttributeError: 'module' object has no attribute 'run'
</module>
我们应该根据下面的链接写hello word http:///docs/0.3/tutorial 代码如下: import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
运行: D:\dev\www>python code.py http://0.0.0.0:8080/
浏览器访问:http://127.0.0.1:8080/
看到hello, world!我们就成功了!
--EOF--
|