【发布时间】:2020-01-10 21:12:11
【问题描述】:
我正在尝试将 functions.js 文件导入使用 python 生成的 html 页面(在本地 CGI 服务器上运行),但无论我如何在 Server.py 脚本中编辑 extensions_map,我都会收到以下消息。
The script from “http://localhost/functions.js” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.
我尝试将很多东西放在functions.js文件中并调用它们,但它不起作用。
服务器.py
import http.server
port = 80
address = ("",port)
server = http.server.HTTPServer
handler = http.server.CGIHTTPRequestHandler
handler.extensions_map=({
'.manifest': 'text/cache-manifest',
'.html': 'text/html',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.svg': 'image/svg+xml',
'.css': 'text/css',
'.js': 'text/javascript',
'': 'application/octet-stream', # Default
})
handler.cgi_directories = ["/"]
httpd = server(address, handler)
httpd.serve_forever()
html 文件:
<html>
<link rel="stylesheet" type="text/css" href="templates\Stylesheet.css">
<head>
<meta charset="UTF-8">
<title>Script In Motion (Prototype)</title>
<script src="functions.js" type="text/javascript"></script>
functions.js 文件
function logtest(){
console.log("test");
}
我尝试使用 extensions_map.update,结果相同。我在某处错过了一步吗?
【问题讨论】:
标签: javascript python server mime-types