我最近在使用Python的SimpleHTTPServer来托管网络文件。我想要一个自定义的404页面,所以我进行了研究并得到了一些答案,但我仍然想要使用这个脚本。那么,我需要添加什么内容才能让这个脚本有404页面呢?
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 80
server_address = ('192.168.1.100', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
print "Being served on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
HandlerClass.error_message_format = ...
的操作。 - user2629998