Skip to content

Instantly share code, notes, and snippets.

@ak64th
Created December 25, 2015 09:40
Show Gist options
  • Save ak64th/eab9ec0497eb9ba9dded to your computer and use it in GitHub Desktop.
Save ak64th/eab9ec0497eb9ba9dded to your computer and use it in GitHub Desktop.
Hello world for flask assets and underscore templates
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)
<!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>
Hello, <%- name %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment