Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Mustache in Python

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 ext
Octocat-spinner-32 pystache
Octocat-spinner-32 tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .gitmodules
Octocat-spinner-32 HISTORY.rst
Octocat-spinner-32 LICENSE
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.rst
Octocat-spinner-32 setup.py
README.rst

Pystache

Inspired by ctemplate and et, Mustache is a framework-agnostic way to render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation: it is impossible to embed application logic in this template language."

Pystache is a Python implementation of Mustache. Pystache requires Python 2.6.

Documentation

The different Mustache tags are documented at mustache(5).

Install It

pip install pystache

Use It

>>> import pystache
>>> pystache.render('Hi {{person}}!', {'person': 'Mom'})
'Hi Mom!'

You can also create dedicated view classes to hold your view logic.

Here's your simple.py:

import pystache
class Simple(pystache.View):
    def thing(self):
        return "pizza"

Then your template, simple.mustache:

Hi {{thing}}!

Pull it together:

>>> Simple().render()
'Hi pizza!'

Test It

nose works great!

pip install nose
cd pystache
nosetests

Author

context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' }
pystache.render("{{author}} :: {{email}}", context)
Something went wrong with that request. Please try again.