【问题标题】:Cannot get .js mimetype to be recognized on local server even with extensions_map edited即使编辑了 extensions_map,也无法在本地服务器上识别 .js mimetype
【发布时间】: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


    【解决方案1】:

    我知道这很愚蠢...我将文件移动到一个子文件夹中并且它起作用了

    【讨论】:

      猜你喜欢
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2011-11-05
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      相关资源
      最近更新 更多