summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pystache/template.py5
-rw-r--r--tests/test_pystache.py5
2 files changed, 9 insertions, 1 deletions
diff --git a/pystache/template.py b/pystache/template.py
index 787304d..c942cd7 100644
--- a/pystache/template.py
+++ b/pystache/template.py
@@ -97,7 +97,10 @@ class Template(object):
@modifier(None)
def render_tag(self, tag_name, context):
"""Given a tag name and context, finds, escapes, and renders the tag."""
- return cgi.escape(unicode(context.get(tag_name, '') or ''))
+ raw = context.get(tag_name, '')
+ if not raw and raw is not 0:
+ return ''
+ return cgi.escape(unicode(raw))
@modifier('!')
def render_comment(self, tag_name=None, context=None):
diff --git a/tests/test_pystache.py b/tests/test_pystache.py
index 4298180..3f21a45 100644
--- a/tests/test_pystache.py
+++ b/tests/test_pystache.py
@@ -27,6 +27,11 @@ class TestPystache(unittest.TestCase):
ret = pystache.render(template, { 'name': 'Jon' })
self.assertEquals(ret, "I think Jon wants a , right Jon?")
+ def test_render_zero(self):
+ template = 'My value is {{value}}.'
+ ret = pystache.render(template, { 'value': 0 })
+ self.assertEquals(ret, 'My value is 0.')
+
def test_comments(self):
template = "What {{! the }} what?"
ret = pystache.render(template)