Python Flask css 不更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21714653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Flask css not updating
提问by ng150716
I am using Flask (the python Package) on my mac, when I first wrote my css it displayed ok. However when I updated it and tried to check it, I only see the first css styles. I have tried restarting the terminal, as well as reinstalling Flask. Any suggestions? Thanks. Heres the HTML:
我在 Mac 上使用 Flask(python 包),当我第一次编写 css 时,它显示正常。但是,当我更新它并尝试检查它时,我只能看到第一个 css 样式。我试过重新启动终端,以及重新安装 Flask。有什么建议?谢谢。继承人的HTML:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<header>
<div class="header"></div>
<div class="logo">
<center><img src="/static/img/p_logo.png" alt="pic"/></center>
</div>
</header>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
And heres the CSS:
继承人的CSS:
* {
font-family: "Times New Roman", Times, serif;
}
header {
background-color: #000000;
width: 100%;
height: 7px;
}
采纳答案by Jacek Kaniuk
Problem is, as already said, related to browser cache.
如前所述,问题与浏览器缓存有关。
To solve that, you could add some dynamic variable to your static (css, js) links. I prefer last modified timestamp for each file.
为了解决这个问题,您可以向静态(css、js)链接添加一些动态变量。我更喜欢每个文件的最后修改时间戳。
/static/css/style.css?q=1280549780
Here is a snippet for that:
这是一个片段:
http://flask.pocoo.org/snippets/40/
http://flask.pocoo.org/snippets/40/
@app.context_processor
def override_url_for():
return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path,
endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)

