私は簡単なHTTPサーバーでフォントを読み込めるようにしようとしていますが、動作させるには小さな四角形しか得られません。pythonシンプルなHTTPサーバーでフォントを読み込めない - 素晴らしいフォント
私はそれがある種のMIMEタイプの問題かもしれないと信じています。 HTMLページとfont-awesomeフォントは、ページがブラウザで直接開かれた場合にロードされますが、単純なHTTPサーバーによってロードされた場合はロードされません。
この質問は同じに見えたが、HTMLコードに
<meta charset="UTF-8">
を配置することは、私を助けていませんでした。 Font awesome not loading when using Python simple http server
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
from os import curdir, sep
import cgi
import subprocess as sub
import time
PORT_NUMBER = 8080
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path=="/":
self.path="/index.html"
try:
sendReply = False
if self.path.endswith(".html"):
mimetype='text/html'
sendReply = True
if self.path.endswith(".jpg"):
mimetype='image/jpg'
sendReply = True
if self.path.endswith(".png"):
mimetype='image/png'
sendReply = True
if self.path.endswith(".gif"):
mimetype='image/gif'
sendReply = True
if self.path.endswith(".svg"):
mimetype='image/svg+xml'
sendReply = True
if self.path.endswith(".css"):
mimetype='text/css'
sendReply = True
if self.path.endswith(".js"):
mimetype='application/javascript'
sendReply = True
if self.path.endswith(".ttf"):
mimetype='application/x-font-ttf'
sendReply = True
if self.path.endswith(".otf"):
mimetype='application/x-font-opentype'
sendReply = True
if self.path.endswith(".woff"):
mimetype='application/font-woff'
sendReply = True
if sendReply == True:
#Open the static file requested and send it
f = open(curdir + sep + self.path, 'rb')
self.send_response(200)
self.send_header('Content-type',mimetype)
self.end_headers()
self.wfile.write(f.read())
f.close()
print(curdir + sep + self.path)
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
def do_POST(self):
if self.path=="/run":
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
#self.send_response(200)
#self.end_headers()
return
これは、HTMLページの一部である:
<html>
<head>
<meta charset="UTF-8">
<title>HW Test</title>
<!-- Bootstrap -->
<link href = "css/bootstrap.min.css" rel="stylesheet"></link>
<link href = "css/custom.css" rel="stylesheet"></link>
<link href = "css/font-awesome.min.css" rel="stylesheet"></link>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class = "container">
<div class="row">
<input id="box1" type="checkbox" />
<label for="box1">Checkbox 1</label>
<input id="box2" type="checkbox" />
<label for="box2">Checkbox 2</label>
</div>
...
チェックボックスがチェックボックスではない、小さな正方形として示されています。 これらはフォントで表示する必要があります。私は問題はフォントファイル名であると思い
はい、それでした。ありがとうございました! – Tobbe