简体   繁体   English

无法下载CSS文件-Flask

[英]CSS file not being downloaded - Flask

I am suddenly having a very odd issue where my browsers (Chrome, Safari, Firefox) are not downloading an external css file. 我突然遇到一个非常奇怪的问题,我的浏览器(Chrome,Safari,Firefox)没有下载外部CSS文件。 I am building a python flask app for heroku. 我正在为heroku构建python flask应用程序。 I am developing on a local server (both gunicorn and the default flask server). 我正在本地服务器(包括gunicorn和默认的flask服务器)上进行开发。 When I load my home page everything seems to load fine except my main stylesheet. 当我加载主页时,除主样式表外,其他所有东西似乎都加载良好。 The <link> node shows up in Chrome devtools under head. <link>节点显示在Chrome devtools的头部下方。

<link rel="stylsheet" href="/static/main.4dd3f5a6.css" type="text/css">

I can click on the href , and a tab opens with my minified css. 我可以单击href ,然后打开一个带有缩小的CSS的标签。 However, when I look under the Resources tab, It does not show the stylesheet. 但是,当我在“ Resources选项卡下查看时,它不会显示样式表。 One of the possible issues I found online, could be that my local server is serving the css with the wrong Content-Type . 我在网上发现的可能问题之一可能是本地服务器为CSS提供了错误的Content-Type However, when I looked under the Network tab to check the Content-Type, the stylesheet doesn't even show up there! 但是,当我查看“ Network选项卡下的“内容类型”时,样式表甚至没有显示在这里! I am using Flask-Assets to load my assets. 我正在使用Flask-Assets加载我的资产。 It seems to work fine for my javascript, just not my css. 它对于我的JavaScript似乎工作正常,但对我的CSS却无效。 Here is some of the relevant code where I set up webassets. 这是我设置网络资产的一些相关代码。

asset_env = Environment(app)
asset_env.debug = True
asset_env.url = app.static_url_path
asset_env.append_path("assets")

js_bundle = Bundle("js/*", filters="jsmin", output="main.%(version)s.js")
css_bundle = Bundle("css/*", "css/font-awesome-4.1.0/css/font-awesome.css",
                    filters="cssmin", output="main.%(version)s.css")
asset_env.register("js", js_bundle)
asset_env.register("css", css_bundle)

I have also tried deploying to my heroku app (it is not in production) and I have the same issue on their server as on my dev server. 我还尝试了部署到我的heroku应用程序(它不在生产中),并且在他们的服务器上和在我的开发服务器上都遇到了同样的问题。

Any ideas? 有任何想法吗?

A bit late to the party, but I had the same problem. 晚会晚了一点,但我遇到了同样的问题。

After moving the type attribute to the front of the link statement, it worked. 将type属性移到link语句的前面后,它就起作用了。

<link type="text/css" href="{{ ASSET_URL }}" rel="stylesheet">

instead of 代替

<link rel="stylsheet" href="{{ ASSET_URL }}" type="text/css">

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

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