public
Last active

pass mustache template into jinja template

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.