javascript - Flask:资源被解释为样式表但以 MIME 类型文本/html 传输

标签 javascript python html css flask

我使用蓝图的 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/

相关文章:

javascript - Firebase云函数 "Function returned undefined, expected Promise or value"

python - 如何表示 tensorflow 中的稀疏特征列表?

javascript - D3.js 不更新数据

javascript - 当我更改输入时,如何在 HTML 表单上自动显示 JavaScript 函数的结果?

javascript - 为什么我的 setState 会导致无限循环?

javascript - HTML5/Javascript/jQuery 音频播放器不响应事件?

python - 将 Python pdfrw PdfReader 对象写入字节/文件流数组

python - sklearn 如何使用多个保存的模型合并和预测数据

html - 我可以重新设计所有 Bootstrap 元素的巨大 'asset page' 吗?

javascript - jQuery 事件处理程序和未声明的事件对象