如何使用存在于Flasks默认静态/目录之外的Flask-Assets捆绑资产?
npm install
将资源下载到bower_components/
javascripts/
assets instance not bound to an application, and no application in current context
例外。任何帮助都会受到赞赏,特别是如果你能给我一个如何管理你的应用程序静态/目录之外的原始+打包资产的例子:P
app/
static/
__init__.py
assets.py
javascripts/
app.js
bower_components/
jquery.js
jquery,pjax,js
from flask.ext.assets import Bundle, Environment
js = Bundle(
'bower_components/jquery.js',
'bower_components/jquery.pjax.js',
'javascripts/app.js'
filters='jsmin',
output='static/packed.js'
)
assets = Environment()
assets.register('js_all', js)
from flask import Flask
from app.assets import assets
app = Flask(__name__)
assets.init_app(app)
答案 0 :(得分:1)
我检查了Flask-Assets源代码,并在FlaskResolver
类的文档字符串中找到了它:
如果设置了
Environment.load_path
,它将用于查找源文件,替换Flask系统。蓝图前缀不再解析。
所以你需要在app / init.py中执行以下操作:
from os.path import abspath, join
app = Flask(__name__)
assets.load_path = abspath(join(app.root_path, '..'))
assets.init_app(app)