Created
October 21, 2012 04:35
-
-
Save lost-theory/3925780 to your computer and use it in GitHub Desktop.
pass mustache template into jinja template
This file contains 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_string, request | |
app = Flask(__name__) | |
app.config['DEBUG'] = True | |
@app.route("/") | |
def index(): | |
#of course you would put these into files | |
jinja_template = """ | |
{# this is a jinja2 comment #} | |
{% block stuff %} | |
<h1>Jinja2</h1> | |
{% for i in range(5) %} | |
<p>Hello {{ name }}!</p> | |
{% endfor %} | |
<h1>Mustache</h1> | |
{{ mustache_template }} | |
{% endblock %} | |
""" | |
mustache_template = """ | |
<p>{{something}}</p> | |
{{#items}} | |
{{#first}} | |
<li><strong>{{name}}</strong></li> | |
{{/first}} | |
{{#link}} | |
<li><a href="{{url}}">{{name}}</a></li> | |
{{/link}} | |
{{/items}} | |
""" | |
return render_template_string(jinja_template, | |
mustache_template=mustache_template, | |
name=request.values.get('name', 'world') | |
) | |
if __name__ == "__main__": | |
app.run(use_debugger=True, use_reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment