我在/ static /目录服务器端有一堆文件,名称如下:
Slide0.html Slide121.html Slide143.html Slide165.html Slide187.html Slide208.html
Slide28.html Slide4.html Slide71.html Slide93.html
Slide100.html Slide122.html Slide144.html Slide166.html Slide188.html Slide209.html
Run Code Online (Sandbox Code Playgroud)
我在相同的域中获取它们,并定期将它们插入到iframe中,它们所做的只是渲染一些图像,但浏览器给出以下错误:
Resource interpreted as Image but transferred with MIME type text/html: "http://localhost:8888/static/Slide66.html".
Run Code Online (Sandbox Code Playgroud)
我试图徒然地将staticfilehandler子类化:
class StaticHandler(tornado.web.StaticFileHandler):
def get(self, path):
abspath = os.path.abspath(os.path.join(self.root, path))
mime_type, encoding = mimetypes.guess_type(abspath)
if mime_type:
self.set_header("Content-Type", mime_type)
if 'Slide' in abspath:
self.set_header('Content-Type',"image/jpg" )
Run Code Online (Sandbox Code Playgroud)
但是错误仍然存在,我该如何调整?
在 Tornado 3.1 中,您可以子类化StaticFileHandler和覆盖get_content_type().
class StaticJSONFileHandler(tornado.web.StaticFileHandler):
def get_content_type(self):
return 'application/json'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1426 次 |
| 最近记录: |