本地Flask实例中有多个静态路径 [英] More than one static path in local Flask instance

查看:650
本文介绍了本地Flask实例中有多个静态路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为我的本地开发人员Flask实例添加更多的静态路径?
我希望有默认的 static 文件夹来存储站点和另一个文件夹的js / css / images文件。 设计以保留我的特定资产。如果存在更好的解决方案,我不希望在 static 中放置 designs 文件夹。

b $ b

解决方案

我一直在使用以下的方法:

$ p $ #自定义静态数据
@ app.route('/ cdn /< path:filename>')
def custom_static(filename):
return send_from_directory(app.config ['CUSTOM_STATIC_PATH' ],filename)

CUSTOM_STATIC_PATH

在模板中:

url_for('custom_static',filename ='foo')}}

em> - 我不确定是否安全;)


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)

The CUSTOM_STATIC_PATH variable is defined in my configuration.

And in templates:

{{ url_for('custom_static', filename='foo') }}

Caveat emptor - I'm not really sure whether it's secure ;)

这篇关于本地Flask实例中有多个静态路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆