unescape HTML in template

2,181 views
Skip to first unread message

Alex

unread,
Aug 8, 2008, 11:27:32 AM8/8/08
to Django users
Hi all.

I'm using HtmlDiff (http://docs.python.org/lib/module-difflib.html) in
my view which returns a string which is a complete HTML table showing
line by line differences between files.

When I pass the string to the template, the code is automatically
escaped. Is there a way to prevent escaping in order to have the table
easily rendered in my template?

Thanks in advance.

Alex

Mike H

unread,
Aug 8, 2008, 11:30:55 AM8/8/08
to django...@googlegroups.com


In your template :

{% autoescape off %}
{{ string_with_the_table_in_it }}
{% endautoescape %}

Cheers,

Mike

alex....@gmail.com

unread,
Aug 8, 2008, 11:47:09 AM8/8/08
to Django users
Or just mark it as safe, so you can do {{ string_with_html_i_trust|
safe }}

Steve Holden

unread,
Aug 8, 2008, 11:48:11 AM8/8/08
to django...@googlegroups.com
I believe you'll find it's the *rendering* that escapes it. There's a
"safe" filter you can use, like so:

{{ content|safe }}

that will mark it as safe to be rendered without escaping.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Alex

unread,
Aug 8, 2008, 11:50:07 AM8/8/08
to Django users
Great! Thanks a lot.

Alex
Reply all
Reply to author
Forward
0 new messages