被官方参考误解:http://webpy.org/cookbook/custom_notfound.zh-cn
不要使用notfound()方法就是了。
# coding:utf-8 import web urls = ( '/', 'index' ) app = web.application(urls, globals()) render = web.template.render('templates/') def my_notfound(): return web.notfound(""" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>pctools</title> </head> <body> 404 </body> </html> """) web.webapi.notfound = my_notfound app = web.application(urls, globals()) if __name__ == '__main__': app.run()