who is escaping my quotes in render_response?

20 views
Skip to first unread message

Liviu Văsuț

unread,
Jul 10, 2011, 11:03:09 AM7/10/11
to ti...@googlegroups.com
(using tipfy 1.0)

After upgrading to the new version of tipfy, my messages stopped working.
I noticed that the generated html page contained the following line:

tipfy.instances.messages.addMessages([{"body": "Authentication
failed. Please try again.", "level": "error"}]);

Digging deeper I reduced the problem to something like this

#######
class BaseHandler(RequestHandler, Jinja2Mixin):
...
def render_response(self, filename, **kwargs):
...
kwargs['messages'] = json_encode('abc')
return super(BaseHandler, self).render_response(filename, **kwargs)
########

This code generates the following line in the html page:

tipfy.instances.messages.addMessages("abc");

This, of course, is not a valid JSON object, but it demonstrates the
problem. How can I revert to the original string (ie. "abc")?

Thanks,
Li

--
Using Opera's revolutionary email client: http://www.opera.com/mail/ on
Fedora 15

Mauro Asprea

unread,
Jul 10, 2011, 3:10:21 PM7/10/11
to ti...@googlegroups.com
maybe is the autoescape setting of the jinja2 templates

Try surrounding the message section with 
{% autoescape false %}

--
You received this message because you are subscribed to the Google Groups "tipfy" group.
To post to this group, send email to ti...@googlegroups.com.
To unsubscribe from this group, send email to tipfy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tipfy?hl=en.


Mauro Sebastián Asprea

E-Mail: mauro...@gmail.com
Mobile: +34 654297582
Skype: mauro.asprea

Algunos hombres ven las cosas como son y se preguntan porque. Otros sueñan cosas que nunca fueron y se preguntan por qué no?. 
George Bernard Shaw



Liviu Văsuț

unread,
Jul 11, 2011, 12:04:17 AM7/11/11
to ti...@googlegroups.com
This one was easy :).
Thanks Mauro, that did the trick.

On Sun, 10 Jul 2011 22:10:21 +0300, Mauro Asprea <mauro...@gmail.com>
wrote:

> maybe is the autoescape setting of the jinja2 templates
>
> Try surrounding the message section with
> {% autoescape false %}
> {% endautoescape %}
> http://jinja.pocoo.org/docs/templates/#autoescape-overrides
>

--

Noah McIlraith

unread,
Jul 11, 2011, 12:07:04 AM7/11/11
to ti...@googlegroups.com
It's cleaner to use the |safe filter.

{{ some_html_code|safe }}

Liviu Văsuț

unread,
Jul 11, 2011, 9:00:23 AM7/11/11
to ti...@googlegroups.com
Thanks, I'll give it a try.

Reply all
Reply to author
Forward
0 new messages