This question already has answers here:
CSS file not refreshing in browser

(15个答案)


3年前关闭。




这是我的元素层次结构:

元素

python - 为什么我的Flask应用程序无法连接到我的CSS文件?-LMLPHP

这是我的HTML文件:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Hello World</title>
        <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='custom.css') }}"/>
    </head>
    <body>
        <h1>Hello World</h1>
    </body>
</html>

我的.py flask文件:
from flask import Flask, render_template, redirect, json, url_for, request, abort
from pymongo import MongoClient

client = MongoClient()
db = client.web_zoo

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('home.html')

if __name__ == "__main__":
    app.run(debug=True)

和我的CSS文件:
body {
    color: green;
}
h1 {
    color: orange;
}

HTML和.py文件可以正常工作,并且HTML呈现并显示在页面上。但是CSS不会改变。它只是以普通的黑色文本显示。

注意:所有这些导入都在这里,就像我在做其他事情一样。我剥离了所有其他东西,仍然有这个问题。

我可以将 bootstrap 链接到它,并且CSS可以工作,但是不能用于我自己的CSS文件。

我查看并尝试了以下解决方案:

CSS Problems with Flask Web App

Application not picking up .css file (flask/python)

best way to override bootstrap css

这可能很明显,但是我被卡住了。有什么帮助吗?提前致谢!

编辑-我现在添加了元素层次结构的图片,而不仅仅是列表。如您所见,其中也有一些其他HTML文件,但是没有使用或引用任何HTML文件。

最佳答案

尝试

Ctrl + Shift + R

在Chrome中重新加载CSS。

在Mac上,请尝试:

CMD + SHIFT + R

09-26 23:32
查看更多