Issue
My Flask app which uses Blueprint can’t display the CSS file in Chrome and IE.
Debug information:
Resource interpreted as Stylesheet but transferred with MIME type text/html
My app has these files:
app.py
templates/index.html
static/style.css
And in my app.py
:
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/static")
In my index.html
:
<link rel="stylesheet" type="text/css" href="{{ url_for('conf_manager.static', filename='style.css') }}" />
I use Chrome to debug and find that the browser can get the file but the type is text/html
not text/css
(but the JavaScript’s type is okay).
So I want to know why this is happening and how to fix it.
Solution
I figured it out. In the main app someone added response.headers["Content-Type"] = 'text/html; CharSet=UTF-8'
, so IE can’t read the CSS.
And my code in app.py
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/static")
should be changed to:
app = Blueprint("conf_manager",
__name__,
template_folder="templates",
static_folder="static",
static_url_path="/conf_manager/static")
Answered By – Tangwz
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0