当前位置: 代码迷 >> Web前端 >> web.py札记 处理404 500
  详细解决方案

web.py札记 处理404 500

热度:212   发布时间:2012-09-06 10:37:01.0
web.py笔记 处理404 500

?

?官方cookbook ? ?http://webpy.org/cookbook/custom_notfound.zh-cn

?

?

?

import web
        
urls = (
    #'/(hello)', 'hello'    #test for notfound
     '/hello', 'hello'      #test for internalerror
)
class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'
	
def notfound():
    return web.notfound("Sorry, the page you were looking for was not found.")

    # You can use template result like below, either is ok:
    #return web.notfound(render.notfound())
    #return web.notfound(str(render.notfound()))

def internalerror():
    return web.internalerror("Bad, bad server. No donut for you.")

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.notfound = notfound
    app.internalerror = internalerror
    app.run()
		

?

?

感觉这个很好用啊

?

为什么越学越觉得java很笨重?

?

?

?

?

?

  相关解决方案