我花了将近一天的时间来弄清楚为什么我的css文件不能与html文件一起使用。所有的堆栈溢出答案均不适用于我。
感谢您在这一点上能获得的任何帮助。我正在运行安装了flask的python 3.8.1,并使用pycharm。Click here to see my file structure screenshot,这是主要的python文件代码:
from flask import Flask , render_template,
app = Flask(__name__)
@app.route('/')
def index( ):
return render_template("index.html" )
if __name__ == '__main__':
app.run( debug=True)
这里是index.html文件代码,我希望CSS显示在此文件上
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<h1> Title </h1>
<h2>Second headline</h2>
<body>This is an orange test6</body>
</head>
<body>
<link rel="stylesheet" type="text/css" href=" {{ url_for('static', filename=' style.css') }}">
</body>
</html>
这是我在pycharm中运行文件时看到的错误:
“ GET / HTTP / 1.1” 200-“ GET /static/%20style.css HTTP / 1.1” 404-
删除多余的空格
href=" {{ url_for('static', filename=' style.css') }}">
^ ^
第二个引起问题。第一个只是错误的形式。