我使用简单的Python服务器使用以下do_GET
方法提供HTML:
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
import mimetypes
import time
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
print(self.path);
if self.path == '/':
self.path = '/v1.html'
try:
self.send_response(200)
mimetype, _ = mimetypes.guess_type(self.path)
self.send_header('Content-type', mimetype)
self.end_headers()
f = open(os.curdir + os.sep + self.path)
self.wfile.write(bytes(f.read(), "UTF-8"))
f.close()
except IOError:
self.send_error(404, 'file not found')
这最初是我的HTML标题:
<head>
<meta charset="utf-8">
<title>Highchart</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<link rel="stylesheet", type="text/css", a href = "v1.css" />
<script src='http://bgrins.github.io/spectrum/spectrum.js'></script>
<link rel='stylesheet' href='http://bgrins.github.io/spectrum/spectrum.css' />
<script src='/external/customEvents.js'></script>
</head>
然而,这一切都是针对用户应该能够脱机使用的应用程序,因此我必须复制所有外部文件并将它们移动到子目录/外部,例如。
<head>
<meta charset="utf-8">
<title>Highchart</title>
<script src="/external/jquery.min.js"></script>
<script src="/external/highcharts.js"></script>
<script src="/external/exporting.js"></script>
<link rel="stylesheet" href = "v1.css" />
<script src='/external/spectrum.js'></script>
<link rel='stylesheet' href='/external/spectrum.css' />
<script src='/external/customEvents.js'></script>
</head>
自更改以来,经常在运行服务器并打开localhost时,尚未加载一个或多个文件。当我切换回包括文件在线版本的链接时,这根本不会发生,并且随着我将更多文件脱机而逐渐变得更糟。
我对服务器等没有任何经验,因此任何有关问题(以及我如何解决它)的指导或提示都将不胜感激!