接上文:http://www.cnblogs.com/tacyeh/p/4790112.html
一、改造helloWorld.py
1 import web 2 3 urls = ('/', 'Home', 4 '/login', 'Login', 5 '/sayhello(.*)', 'SayHello',)#这里用到了正则表达式 6 class Home: 7 def GET(self): 8 return "<H1>This is home page.</H1>" 9 class Login: 10 def GET(self): 11 return "this is login" 12 class SayHello: 13 def GET(self, name): 14 name = "world" if not name or name.strip(" /") == "" else name.strip(" /") 15 return "hello, %s." % name 16 17 if __name__ == "__main__": 18 app = web.application(urls, globals()) 19 app.run()
二、测试效果: