文件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',它可能对你很有用,因为你不需要破坏你的静态设置来提供一次性服务,关闭页面。 –