Skip to main content

Mustache for Python

Project description

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. It has been tested with Python 2.6.1.

Documentation

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

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!

easy_install nose
cd pystache
nosetests

Author

context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' }
pystache.render("{{author}} :: {{email}}", context)

History

0.3.0 (2010-05-03)

  • View.template_path can now hold a list of path

  • Add {{& blah}} as an alias for {{{ blah }}}

  • Higher Order Sections

  • Inverted sections

0.2.0 (2010-02-15)

  • Bugfix: Methods returning False or None are not rendered

  • Bugfix: Don’t render an empty string when a tag’s value is 0. [enaeseth]

  • Add support for using non-callables as View attributes. [joshthecoder]

  • Allow using View instances as attributes. [joshthecoder]

  • Support for Unicode and non-ASCII-encoded bytestring output. [enaeseth]

  • Template file encoding awareness. [enaeseth]

0.1.1 (2009-11-13)

  • Ensure we’re dealing with strings, always

  • Tests can be run by executing the test file directly

0.1.0 (2009-11-12)

  • First release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystache-0.3.0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file pystache-0.3.0.tar.gz.

File metadata

  • Download URL: pystache-0.3.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pystache-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0aac3879b419f1bd3bb517b852e27352e612226855150f4a1a2f7c9d0a4cdcd6
MD5 1b03563faf7b63c255ad21e12ffdbd6c
BLAKE2b-256 93d4ee13d28c8f3f7f49de9fdbed209cc1aa35d56a9b53a2eece17bf340f9ac9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page