Simple mustache templating for Flask applications


$ pip install flask-stache

Getting Started

There are two methods of rendering templates when using Flask-Stache: The render_view and render_template methods. They are used like so:

from flask import Flask
from flask_stache import render_view, render_template

class Home(object):
    def msg(self):
        return "Home"

app = Flask(__name__)
app.debug = True

def home():
    return render_view(Home())

def about():
    return render_template('about/index', msg="About")

Notice the view object named Home used with render_view. The template for this view should be a file named home.mustache and located at the root of the application’s template folder:


Now notice the use of render_template in the about view. This should look familiar to Flask’s render_template method. Simply pass the name of the template and the template context to this method. The template for the about viewshould be a file named index.mustache and located in a subfolder of the application’s template folder named about:


The main difference here is that file extensions are not necessary.