文件index.html
是靜態的,因此通過render_template()
傳遞它將是浪費。如果我store index.html
under static/
和使用app = Flask(__name__)
,一切都很好。如何使用平面燒瓶目錄層次結構?
但如果我點static_url_path=''
到根,並保持index.html
在同一個文件夾中Python應用程序,我得到
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()
如何使用完全平坦的目錄層次結構,將上面的兩個文件保存在同一個目錄中?
我會鼓勵你通過瓶提供靜態頁面,如果這就是你需要做的。 查看'static_folder',而不是'static_url_path'。 查看[此帖子](http://stackoverflow.com/a/20648053/3261863)對於'send_from_directory',它可能對你很有用,因爲你不需要破壞你的靜態設置來提供一次性服務,關閉頁面。 –