Python http服务器:如何打开indexOtherName.html?

2024-04-25 08:49:30 发布

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

我使用的是python3web服务器。我有四个网页,我正在开发,需要在不同的时间在浏览器中查看,说index1.html,index2.html,index3.html,index4.html。这些文件依赖于子文件夹中的样式表和脚本。你知道吗

在我的CLI中,我使用:python -m http.server启动服务器

还有别的命令吗localhost:8000将显示特定文件而不是默认文件索引.html?你知道吗

谢谢


Tags: 文件服务器脚本文件夹网页clihtml时间
1条回答
网友
1楼 · 发布于 2024-04-25 08:49:30

不幸的是没有。你知道吗

如果你看看http.server源代码在https://github.com/python/cpython/blob/3.7/Lib/http/server.py#L687-L693,您将看到它只在当前目录中搜索索引.html或者索引.htm如果找不到,则返回目录列表。你知道吗

for index in "index.html", "index.htm":
    index = os.path.join(path, index)
    if os.path.exists(index):
        path = index
        break
else:
    return self.list_directory(path)

此外,没有命令行参数仅为单个文件提供服务。见https://github.com/python/cpython/blob/3.7/Lib/http/server.py#L1240-L1262

相关问题 更多 >

    热门问题