0

私のプロジェクトの構造は次のとおりです。

templates
    index.html
static
    style.css
testFlask.py

style.cssurl_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 を再作成したところ、すべてが正常になりました。ご清聴ありがとうございました!

4

1 に答える 1

1

ここでコード/テンプレート スニペットをフラスコ 0.8 (Debian パッケージのバージョン) でテストしましたが、問題を再現できません -> style.css が見つかりました。おそらく、静的ディレクトリのアクセス許可は制限されていますか? testFlask.py を実行するユーザーの静的ディレクトリへの読み取りアクセスを削除すると、404 が表示されます。

よろしくお願いします、 マティアス

于 2012-12-21T23:35:58.053 に答える