【发布时间】:2022-01-23 23:11:32
【问题描述】:
我需要从烧瓶中的文件夹中公开一些图标,如下所示:
PROJECT NAME
>> static
>> assets
>> icon-16.png
>> icon-32.png
>> icon-64.png
>> icon-80.png
>> icon-120.png
>> logo-filled.png
>> templates
>> commands.html
>> index.html
>> taskpane.html
>> app.py
我需要使assets 可路由,这样我就可以从这样的网址访问 png 文件:
https://pythonlinuxtest.azurewebsites.net/assets/icon-16.png
https://pythonlinuxtest.azurewebsites.net/assets/icon-32.png
https://pythonlinuxtest.azurewebsites.net/assets/icon-64.png
这是我目前的app.py 中的内容:
from flask import Flask
from flask import render_template
app = Flask(__name__)
# @app.route("/")
# def hello():
# return "Hello, World!"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/taskpane.html")
def taskpane():
return render_template("taskpane.html")
@app.route("/commands.html")
def commands():
return render_template("commands.html")
我不确定如何将 assets 目录添加到 app.py 以便可以访问 png 文件。
【问题讨论】:
-
最有效的方法是让http服务器来服务静态文件。见这里:stackoverflow.com/questions/20646822/…