ファイルindex.html
は静的であるため、render_template()
に渡すのは無駄です。 I store index.html
under static/
とapp = Flask(__name__)
を使用すると、すべて正常です。フラットFlaskディレクトリ階層はどのように使用しますか?
私はルートにstatic_url_path=''
を指し、Pythonアプリケーションと同じフォルダにindex.html
を続けるなら、私が手
127.0.0.1 - - [21/Nov/2016 14:35:54] "GET/HTTP/1.1" 404 -
index.htmlを
<!DOCTYPE html>
<head></head>
<body>
<h2>Hello, World!</h2>
</body>
の.py
from flask import Flask, current_app
app = Flask(__name__, static_url_path='')
@app.route('/')
def hello_world():
return current_app.send_static_file('index.html')
if __name__=="__main__":
app.run()
上記の2つのファイルを同じディレクトリに保存して、完全にフラットなディレクトリ階層を使用するにはどうすればよいですか?
が、私はそれがすべてを行う必要かどうフラスコを通じて、静的なページを提供するからあなたを阻むだろう。 'static_url_path'の代わりに' static_folder'を見てください。 'send_from_directory'のための[this post](http://stackoverflow.com/a/20648053/3261863)を参照してください。これは静的な設定を片方向のサービスとして扱う必要がないので、オフページ。 –