私のプロジェクトの構造は次のとおりです。
templates
index.html
static
style.css
testFlask.py
style.css
(url_for
または手動で)追加しようとしましたが、URLlocalhost:5000/static/style.css
は言うPage not found
testFlask.py のコード:
from flask import Flask, render_template, request, session, g, redirect, url_for,flash
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
index.html からのコード:
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
最後に、style.css を再作成したところ、すべてが正常になりました。ご清聴ありがとうございました!