如何在使用pythonsimplehtp时更改默认404页

2024-04-24 22:23:17 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用命令启动http服务器时:

python -m SimpleHTTPServer

如何更改默认的404页?在


Tags: 命令httpsimplehttpserver服务器时
1条回答
网友
1楼 · 发布于 2024-04-24 22:23:17

使用命令行,这是不可能的。在

您应该制作如下脚本:

import BaseHTTPServer
import SimpleHTTPServer

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    error_message_format = '''
    custom error message
    '''

BaseHTTPServer.test(MyHandler, BaseHTTPServer.HTTPServer)

相关问题 更多 >