简体   繁体   English

Flask Css 文件即使在重新加载后也不起作用

[英]Flask Css file doesn't work even after reload

I have been stuck with this for hours, and haven't found an answer anywhere... I am creating a simple web app with python+flask and i want to apply styling for my page, but it simply doesn't work, and there is no error.我已经坚持了几个小时,但在任何地方都没有找到答案......我正在使用 python+flask 创建一个简单的网络应用程序,我想为我的页面应用样式,但它根本不起作用,并且没有错误。 Directories are as follows style.css is in static folder, profile.html in templates folder目录如下style.css 在 static 文件夹中,profile.html 在 templates 文件夹中

from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/profile/<name>')
def profile(name):
     return render_template("profile.html",name=name)
if __name__=="__main__":
     app.run(debug=True)

That is the code from app.py file.那是 app.py 文件中的代码。

Now my html looks like this.现在我的 html 看起来像这样。

<!doctype html>
<title> Welcome </title>
<link rel = "stylesheet" type="text/css" herf="{{ url_for('static', filename='style.css') }}" />
<h1>Hey there YOU {{name}}</h1>

I was looking up on the internet for solutions, and usualy, the problem is in the link, or browser cache.我在互联网上寻找解决方案,通常,问题出在链接或浏览器缓存中。 I tried reloading brower, opening with different browers and so on, but it doesn't seem to help...我尝试重新加载浏览器,使用不同的浏览器打开等等,但似乎没有帮助...

Also my css file if needed...如果需要,还有我的 css 文件...

h1 {
     padding: 100px;
     color: blue;
}

You've mistyped the href attribute in <link> .您在<link>错误的href属性。 It should be href but you've typed herf instead.它应该是href但你输入了herf

Little tip for next time: open the Network tab of your browser's dev tools and check that all the assets you need/expect are 1) fetched and 2) fetched successfully.下次小提示:打开浏览器开发工具的“ Network选项卡,检查您需要/期望的所有资产是否 1) 已获取和 2) 已成功获取。

You can also look into adopting an editor that will warn you of typos like these.您还可以考虑采用一种编辑器,该编辑器会警告您出现此类拼写错误。

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

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