Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pystache without escaping (unescaped)

I'm using pystache to render the templates. I'm getting & in the output when I render context variables having &. How can get rid of & where I need & . Same thing is happening with django templating as well

>>> pystache.render('The URL {{URL}}', {'URL': 'http://google.com?a=3&b=3'})
u'The URL http://google.com?a=3&b=3'
like image 282
neotam Avatar asked Jan 16 '16 16:01

neotam


1 Answers

To prevent escaping use triple braces {{{var}}}

To prevent escaping, use triple braces, {{{URL}}} instead of double braces {{URL}}

>>> pystache.render('The URL {{{URL}}}', {'URL': 'http://google.com?a=3&b=3'})
u'The URL http://google.com?a=3&b=3'

I've tested this on the most recent release as of today, version 0.5.4

Mustache Documentation

Since Pystache is a Mustache implementation in Python, you can use Mustache's documentation as pointers.

All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.

source: https://mustache.github.io/mustache.5.html

like image 141
bakkal Avatar answered Oct 06 '22 00:10

bakkal