Turning jinja autoescape OFF

1,953 views
Skip to first unread message

stratosgear

unread,
Apr 17, 2011, 6:23:49 AM4/17/11
to tipfy
Hi,

I am using tipfy 1.0b1.

It seems that Jinja's autoescape is automatically turned on. I can
turn it off by editing lib/dist/tipfyext/jinja2/__init__.py and
modifying the default_config variable and passing autoescape: False in
the environment_args, but is this the right way?

The README.txt of the /lib/dist folder has a warning:

This directory is removed every time the buildout tool runs, so don't
place
or edit things here because any changes will be lost!

Thanks,

Stratos

Hannes Rydén

unread,
May 5, 2011, 7:46:29 AM5/5/11
to tipfy
I think the correct way is to edit your config.py and add the
following line:
config['tipfyext.jinja2'] = {
'environment_args': {
'autoescape': False,
},

Mauro Asprea

unread,
May 6, 2011, 3:21:55 AM5/6/11
to ti...@googlegroups.com

U can also use
{% autoescape off%}
Blabla content unescaped
{% end autoescape %}

In a template

> --
> 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 Asprea

unread,
May 6, 2011, 3:52:54 AM5/6/11
to ti...@googlegroups.com
Sorry, it is like this:

{% autoescape False %}

Something here in your template

{% endautoescape %}

--
Mauro Sebastián Asprea

E-Mail: mauro...@gmail.com
Mobile: +34 654297582
Skype: mauro.asprea
http://www.wishandbam.com/

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

stratosgear

unread,
May 6, 2011, 10:23:46 AM5/6/11
to ti...@googlegroups.com
Mauro,

I would prefer to have to Autoescape, by default, off. That way I can include templates inside templates without escaping.

In case I will be outputting any user content and I want to be a little more carefull, I would then use the {% autoescape True %} in the appropriate places.

I will try what Hannes suggested and I will post again.

Thanks.

Noah McIlraith

unread,
May 11, 2011, 10:49:25 PM5/11/11
to ti...@googlegroups.com
If there are only a few instances where you don't want it to be escaped, you could use the |safe filter.

{{ dont_escape_this|safe }}

It's generally best to consider everything dangerous unless explicitly stated otherwise. Unless you are using the template to generate something other than HTML and similar formats, autoescape should be on.
Reply all
Reply to author
Forward
0 new messages