Flask-Stache

Simple mustache templating for Flask applications

Installation

$ 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

@app.route('/')
def home():
    return render_view(Home())

@app.route('/about')
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:

<app_root>/templates/home.mustache

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:

<app_root>/templates/about/index.mustache

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

API