gpt4 book ai didi

python - 自定义简单的 Python HTTP 服务器不提供 css 文件

转载 作者:太空狗 更新时间:2023-10-29 22:06:09 25 4
gpt4 key购买 nike

我发现用python写的,一个很简单的http服务器,它的do_get方法是这样的:

def do_GET(self):
try:
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers();
filepath = self.path
print filepath, USTAW['rootwww']

f = file("./www" + filepath)
s = f.readline();
while s != "":
self.wfile.write(s);
s = f.readline();
return

except IOError:
self.send_error(404,'File Not Found: %s ' % filepath)

它工作正常,除此之外 - 它不提供任何 css 文件(它在没有 css 的情况下呈现)。有人对这个怪癖有建议/解决方案吗?

最好的问候,真理报

最佳答案

您明确将所有文件作为 Content-type: text/html 提供,而您需要将 CSS 文件作为 Content-type: text/css 提供。参见 this page on the CSS-Discuss Wiki了解详情。 Web 服务器通常有一个查找表来将文件扩展名映射到内容类型。

关于python - 自定义简单的 Python HTTP 服务器不提供 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/947372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com