目前正在嘗試學習 Flask,我正在嘗試路由到一個 HTML 文件,該文件從樣式表加載一些 CSS,從 .js 文件加載一些 Javacript。 HTML、CSS 和 JS 文件來自我之前處理過的前端項目,因此我最初只是將這些文件復制到目錄中。 當失敗時,我做了一些研究,發現我需要創建一個靜態文件夾並更改鏈接到樣式表和腳本的方式。 但是,這仍然不起作用。
燒瓶片段:
@app.route('/landing')
def landingPage():
return render_template("index.html")
HTML 片段 (index.html):
<head>
...
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles.css') }}">
<script src="{{ url_for('static',filename='app.js') }}" defer> </script>
</head>
根目錄包含 app.py(Flask 文件),子目錄模板包含 index.html,子目錄 static 包含樣式.css 和 app.js。
在控制台中,由於無法加載源為 127.0.0.1:5000/static/app.js 的腳本,我收到錯誤消息。 有趣的是,該文件被稱為landing.html 而不是index.html,但我認為這與我的問題無關(如果我錯了,請告訴我)。
先感謝您,