我想使用 flask-assets 来组织我的 webassets 和 mako 进行模板化。Flask-assets 通常通过以下方式使用 jinja:
{% assets "js_all" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
Mako 等价物(据我所知)如下:
% assets 'coffee':
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
% endassets
但是,这会导致编译错误:
mako.exceptions.CompileException
CompileException: Unsupported control keyword: 'assets' in file '/index.html' at line: 8 char: 1
有没有办法在 Mako 中使用自定义控制关键字(如“资产”)?
这是我的 app.py 记录:
import os
from flask import Flask, render_template
from flask.ext import assets
from flask import config
from flask.ext.mako import MakoTemplates
from flask.ext.mako import render_template
app = Flask(__name__)
app.config['ASSETS_DEBUG'] = True
mako = MakoTemplates(app)
env = assets.Environment(app)
# Tell flask-assets where to look for our coffeescript and sass files.
env.load_path = [
os.path.join(os.path.dirname(__file__), 'js'),
os.path.join(os.path.dirname(__file__), 'styles'),
]
coffee = assets.Bundle('**/*.coffee', filters='coffeescript', output="app.js")
env.register('coffee', coffee)
@app.route("/")
def index():
return render_template('index.html', name='mako')
if __name__ == "__main__":
app.run(debug=True)