Created
December 25, 2015 09:40
-
-
Save ak64th/eab9ec0497eb9ba9dded to your computer and use it in GitHub Desktop.
Hello world for flask assets and underscore templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
from flask_assets import Bundle, Environment | |
app = Flask('app') | |
app.config['JST_COMPILER'] = u'_.template' | |
app.config['JST_NAMESPACE'] = 'window.Templates' | |
app.config['JST_BARE'] = False | |
env = Environment() | |
template_bundle = Bundle( | |
'index.jst', | |
filters='jst', | |
output='templates.js' | |
) | |
env.register({'templates': template_bundle}) | |
env.init_app(app) | |
@app.route('/') | |
def index(): | |
return render_template('index.html') | |
if __name__ == '__main__': | |
app.run(debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
</head> | |
<body> | |
<script type="text/javascript" src="{{ url_for('static', filename='underscore.js') }}"></script> | |
{% assets "templates" %} | |
<script type="text/javascript" src="{{ ASSET_URL }}"></script> | |
{% endassets %} | |
<script type="text/javascript"> | |
document.body.innerHTML = Templates.index({name:'world'}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, <%- name %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment