我使用蓝图的 Flask 应用无法在 Chrome 和 IE 中显示 CSS 文件。
调试信息:
Resource interpreted as Stylesheet but transferred with MIME type text/html
我的应用有这些文件:
app.py
templates/index.html
static/style.css
在我的 app.py
中:
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/static")
在我的 index.html
中:
<link rel="stylesheet" type="text/css" href="{{ url_for('conf_manager.static', filename='style.css') }}" />
我用Chrome调试,发现浏览器可以获取到文件,但是类型是text/html
,不是text/css
(但是JavaScript的类型没问题) .
所以我想知道为什么会发生这种情况以及如何解决它。
最佳答案
我想通了。在主应用程序中,有人添加了 response.headers["Content-Type"] = 'text/html; CharSet=UTF-8'
,所以IE无法读取CSS。
还有我的代码在app.py
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/static")
应该改为:
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/conf_manager/static")
关于javascript - Flask:资源被解释为样式表但以 MIME 类型文本/html 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34260838/