小编典典
我认为无论出于何种原因,你都想使用自定义路径访问静态文件夹。我希望这样做是为了更好的应用程序模块化。
这是我的应用程序文件夹结构:
instance/
core/
|_templates/
|_static/
|_views.py
run.py
config.py
如你所见,我的static文件夹位于该core文件夹内。
在中run.py,你可以执行以下操作:
app = Flask(__name__, static_url_path=None)
if __name__ == '__main__':
app.config.from_object('config')
# config file has STATIC_FOLDER='/core/static'
app.static_url_path=app.config.get('STATIC_FOLDER')
# set the absolute path to the static folder
app.static_folder=app.root_path + app.static_url_path
print(app.static_url_path)
print(app.static_folder)
app.run(
host=app.config.get('HOST'),
port=app.config.get('PORT'),
threaded=True
)
这就是我所做的,并且效果很好。我正在使用flask0.12。
2020-04-07