【发布时间】:2014-02-19 06:39:49
【问题描述】:
现在我有这个文件结构
server-
|
|css-
| |bad.css
|
|html-
| |bad.html
|
|jpg-
| |bad.jpg
|
|server.py
这很糟糕。css:
body
{
background-image:url('bad.jpg');
background-repeat:no-repeat;
background-position:right top;
margin-right:200px;
}
这很糟糕。html:
<html>
<head>
<link rel="stylesheet" type="text/css" href="bad.css">
</head>
<body>
<h1>This isn't a thing!</h1>
<p>You must be mistaken. But <a href="/index">here</a> is where you can find your way again.</p>
</body>
</html>
这是 server.py 的相关部分
from BaseHTTPServer import BaseHTTPRequestHandler as Handler
from mime types import guess_type
class MyHandler(Handler):
def do_GET(self):
print self.path
print self.headers
extensions = ['html', 'css', 'jpg']
fname = self.path
for ext in extensions:
if fname.endswith(ext):
fname = ext + fname
break
if fname.split('/')[0] == '':
fname = 'html/bad.html'
mimetype = guess_type(fname)[0]
print fname
data = open(fname, 'rb')
self.send_response(200)
self.send_header('Content-type', mimetype)
self.end_headers()
self.wfile.write(data.read())
data.close()
我更新的代码应该已经修复了它,但现在我的浏览器根本不呈现它,它只是显示 html 代码。
【问题讨论】:
-
首先,问题是什么,你说
From what I've gathered via google, the problem is with ...,你在谷歌上研究什么“问题”? -
@vikki stackoverflow.com/questions/947372/… 问题是没有 css 渲染。当我将浏览器指向我的服务器时,我看不到图像,只有 html。
标签: python html css mime-types