我有一个 Flask 应用程序使用 pypandoc 从 markdown 生成和提供静态 HTML。一切顺利,但 css 文件作为
text/html
而不是 text/css
,因此它没有被解释。
Firefox/Chromium 给出以下错误:
The stylesheet http://127.0.0.1:5000/static/notes.css was not loaded because its MIME type, “text/html”, is not “text/css”.
在 Flask 应用程序中(使用 pypandoc 命令提取)
...
css = url_for('static', filename='notes.css')
vcss = '--css='+css
pdoc_args = ['--template=templates/notes.html',
vcss
]
output = ppandoc.convert_text(mdblop, 'html', format='markdown', extra_args=pdoc_args, outputfile=filename)
with open(filename) as fp:
htmlpage = fp.read()
return htmlpage
...
在Pandoc模板中
notes.html
$for(css)$
<link type="text/css" rel="stylesheet" href="$css$" />
$endfor$
我添加了
type="text/css"
试图强制类型,但它没有帮助/改变。
CSS文件
notes.css
是一个标准的CSS文件。
在 Flask 提供的最终 HTML 中:
<link type="text/css" rel="stylesheet" href="/static/notes.css" />
Flask 似乎没有将这个静态文件正确地视为
text/css
类型。