Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created October 21, 2012 04:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lost-theory/3925780 to your computer and use it in GitHub Desktop.
Save lost-theory/3925780 to your computer and use it in GitHub Desktop.
pass mustache template into jinja template
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