本地 Flask 实例中有多个静态路径 [英] More than one static path in local Flask instance
本文介绍了本地 Flask 实例中有多个静态路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为我的本地开发 Flask 实例添加更多静态路径?我想要默认的 static
文件夹来存储站点和另一个文件夹的 js/css/images 文件,例如designs
保留我的特定资产.如果存在更好的解决方案,我不想将 designs
文件夹放在 static
中.
Is that possible to add more static paths for my local dev Flask instance?
I want to have default static
folder for storing js/css/images files for the site and another folder, e.g. designs
to keep my specific assets. I don't want to place designs
folder inside static
if there is a better solution exists.
推荐答案
我一直在使用以下方法:
I have been using following approach:
# Custom static data
@app.route('/cdn/<path:filename>')
def custom_static(filename):
return send_from_directory(app.config['CUSTOM_STATIC_PATH'], filename)
CUSTOM_STATIC_PATH
变量在我的配置中定义.
The CUSTOM_STATIC_PATH
variable is defined in my configuration.
在模板中:
{{ url_for('custom_static', filename='foo') }}
Caveat emptor - 我不确定它是否安全 ;)
Caveat emptor - I'm not really sure whether it's secure ;)
这篇关于本地 Flask 实例中有多个静态路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文