繁体   English   中英

使用Flask在Heroku上为.htc文件添加MIME类型

[英]Add MIME type for .htc files on Heroku with Flask

我试图在我的CSS中包含PIE.htc(http://www.css3pie.com/)文件,以解决IE中的某些问题。 我喜欢这条线

behavior: url(/static/pie/PIE.htc);

有关的课程。 这似乎没有加载。

通过阅读,看来我需要添加MIME类型

text/x-component 

我的使用Flask的Heroku应用程序中的.htc文件。

有人对如何执行此操作有任何想法吗?

谢谢。

更新:

我认为也许类似于以下内容的方法会起作用,但似乎无效。

@app.route('/PIE.htc')
def pie():
    handle = open('static/pie/PIE.htc','r+')
    return Response(handle, mimetype = 'text/x-component')

您的代码对我有用。 这是我完整的测试应用程序:

import flask

app = flask.Flask(__name__)

@app.route('/')
def index():
    handle = open(__file__, 'r+') 
    return flask.Response(handle, mimetype='test/x-component')

if __name__ == "__main__":
    app.run(debug=True)

这可以在HTTP响应中为其提供所需的Content-Type: test/x-component标头。

运行我的测试应用程序:

(test)day@office:~/test$ python test.py
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

在另一个终端中,使用curl仅为标题发送HEAD请求:

day@office:~$ curl -Is http://127.0.0.1:5000/
HTTP/1.0 200 OK
Content-Type: test/x-component
Connection: close
Server: Werkzeug/0.8.3 Python/2.7.3
Date: Fri, 30 Nov 2012 00:29:39 GMT

如果这在本地运行时也对您有用,那么它可能与Heroku运行时环境有关? 我对Heroku并不熟悉,但是也许他们在反向代理后面运行您的应用,该反向代理吃了未配置为处理的Content-Type?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM