[英]Flask unable to serve static file(css)
I have a simple flask app:我有一个简单的烧瓶应用程序:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('basic.html')
if __name__ == '__main__':
app.run(debug=True)
Directory structure(as recommended):---目录结构(推荐):---
\templates
\basic.html
\static
\basic.css
basic.py
And I have connected my CSS file in the HTML using:---我已经使用以下方法在 HTML 中连接了我的 CSS 文件:---
<link rel="stylesheet" href="{{ url_for('static', filename='basic.css') }}">
The problem: The changes I'm making to my CSS file aren't taking place in my app/website even after reloading the browser and when I checked the sources in developer tool it turns out that the styling isn't applied!问题:即使在重新加载浏览器之后,我对我的 CSS 文件所做的更改也不会发生在我的应用程序/网站中,并且当我在开发人员工具中检查源代码时,结果发现样式未应用! This is my CSS file:--
这是我的 CSS 文件:--
h2{
font-size: 50px;
color: red;
background-color: green;
}
p{
color: blue;
}
h3{
font-size: 100px;
color: green;
background-color: red;
}
h4{
color: purple;
background-color: blue;
}
And this is what is shown in the developer tools:--这就是开发人员工具中显示的内容:--
h1{
font-size: 50px;
color: red;
background: green;
}
p{
color: blue;
}
I looked at other answers too ( Here ) but I'm unable to understand what exactly am I doing wrong!我也看了其他答案( 这里),但我无法理解我到底做错了什么!
Edit: I'm not seeing the changes after navigating to the file in the browser too:--编辑:在浏览器中导航到文件后我也没有看到更改:--
Edit 2: Okay!编辑2:好的! The hard refresh way(Ctrl + shift + R) is working but I have to do it every time I make any change!
硬刷新方式(Ctrl + shift + R)正在工作,但每次我进行任何更改时都必须这样做! Isn't there any other way ?
没有其他办法了吗?
as you know this is one the most problem from a flask framework.如您所知,这是烧瓶框架中最大的问题之一。 I didn't find any technical stack for solving this.
我没有找到解决这个问题的任何技术堆栈。 but you can clear all of your browser cookies or clear the localhost histories as a running on your local host.
但你可以清除所有浏览器Cookie或清除本地主机上的本地主机历史的运行。 in addition if you changing your browser it will be working done.
此外,如果您更改浏览器,它将正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.