TG 2.2.2. Problems parsing Jinja templates

31 views
Skip to first unread message

León Domingo

unread,
Apr 11, 2013, 7:41:23 AM4/11/13
to turbogea...@googlegroups.com
Hi people,

Right now I'm using TG 2.2.0 and I've tried TG 2.2.2 but I have problems during template parsing.
I use Jinja2 (2.6) and use_dotted_templatenames = False and don't use .jinja extension for templates, but .html, .js, etc.

The problem is that everything is escaped so if I have something like this:

  import simplejson as sj

  class AController(BaseController):
      @expose('foo/bar/my_template.html')
      def my_template(self):
          something = sj.dumps(dict(foo='foo', bar='bar'))
          return dict(something=something)

Then inside the HTML template (foo/bar/my_template.html)

<html>
<body>
<script>
    var something = {{something}};
    console.log(something.foo); // 'foo'
    console.log(something.bar); // 'bar'
</script>
</body>
</html>


This ain't work because {{something}} is escaped to be HTML-suited instead of its "raw" format.

Same thing happens with the default error page. Instead of

We're sorry but we weren't able to process this request.

I get

<p>We're sorry but we weren't able to process this request.</p>

Does anybody know what's going on?

I have say that this happen with an existing app, upgrading TG2 version from 2.2.0 to 2.2.2. I simply use another virtual environment.

Thanks

Regards,
León

 

Alessandro Molina

unread,
Apr 11, 2013, 11:02:00 AM4/11/13
to tg-trunk
Starting from 2.2.1 Jinja has autoescaping enabled by default like all the other template engines did. This makes so that TurboGears has a consistent behavior of escaping independently from the engine used.

You can update your code using markupsafe.Markup to mark parts that should not be escaped or explicitly disable the escaping using a before_config hook to change base_config['pylons.app_globals'].jinja2_env.autoescape to False.




 

--
You received this message because you are subscribed to the Google Groups "TurboGears Trunk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears-tru...@googlegroups.com.
To post to this group, send email to turbogea...@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears-trunk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

León Domingo

unread,
Apr 11, 2013, 1:29:01 PM4/11/13
to turbogea...@googlegroups.com
Ok. Thanks, Alessandro

León
Reply all
Reply to author
Forward
0 new messages