Css错误“ GET /static/%20style.css HTTP / 1.1” 404-使用Pycharm 3.8.1

问题描述 投票:0回答:1

我花了将近一天的时间来弄清楚为什么我的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-

html css flask pycharm http-status-code-404
1个回答
0
投票

删除多余的空格

href=" {{ url_for('static', filename=' style.css') }}">
      ^                               ^

第二个引起问题。第一个只是错误的形式。

© www.soinside.com 2019 - 2024. All rights reserved.