【发布时间】:2020-10-29 11:34:40
【问题描述】:
我有一个简单的烧瓶应用程序:
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)
目录结构(推荐):---
\templates
\basic.html
\static
\basic.css
basic.py
我已经在 HTML 中连接了我的 CSS 文件:---
<link rel="stylesheet" href="{{ url_for('static', filename='basic.css') }}">
问题:即使在重新加载浏览器之后,我对 CSS 文件所做的更改也没有发生在我的应用程序/网站中,当我在开发人员工具中检查源代码时,发现样式未应用! 这是我的 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;
}
这就是开发者工具中显示的内容:--
h1{
font-size: 50px;
color: red;
background: green;
}
p{
color: blue;
}
我也看了其他答案 (Here) 但我无法理解我到底做错了什么!
编辑:在浏览器中导航到文件后我也没有看到更改:--
编辑 2:好的! 硬刷新方式(Ctrl + shift + R) 是有效的,但我每次进行任何更改时都必须这样做! 没有别的办法吗?
【问题讨论】:
-
你如何在 HTML 中调用它?
-
这可能有多种原因,您可以尝试调试它,检查 html 你的 css 静态文件路径是什么,然后导航到那里看看里面有什么,在你的情况下它是
http://127.0.0.1:5000/static/basic.css,如果您看到旧的更改,那么也许您必须硬刷新(如 Ctrl + Shift + R)或尝试隐身浏览器或重新启动您的烧瓶服务器 -
我也遇到过同样的问题,这是因为浏览器缓存。只需硬重新加载,它就会成功更新(我同意@Shashank)
-
@Anrar Ahmed。我已经提到过:我使用 `` 链接它们
-
@Shashank 即使在浏览器中导航到该 css 文件后,我也没有看到更改!
标签: python css python-3.x flask