即使编辑了extensions_map,也无法在本地服务器上识别.js模仿类型

问题描述 投票:0回答:1

[我正在尝试将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文件中并调用它们,但不起作用。

Server.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,结果相同。我在某处错过了一步吗?

我正在尝试将functions.js文件导入由python生成的html页面(在本地CGI服务器上运行),但是无论我如何在...中编辑extensions_map,我都始终收到以下消息:] >>

我知道这有点刻薄...我将文件移到一个子文件夹中并且可以正常工作

javascript python server mime-types
1个回答
0
投票

我知道这有点刻薄...我将文件移到一个子文件夹中并且可以正常工作

© www.soinside.com 2019 - 2024. All rights reserved.