html is rendering as string in templates

1,644 views
Skip to first unread message

deepu

unread,
Oct 29, 2011, 5:45:47 AM10/29/11
to Tornado Web Server
Hi,
i used to use tornado 1.2 for an app of mine. everything worked
well. Now Updated to latest version and changed couple of things in
the templates like

previously {{ module ForumPost() }} to {% module ForumPost() % } etc.

The issue i am facing is that now the html is being rendered as a
string because of which the browser is not parsing the html and
renders the entire html as a string.

I am pretty sure i didn't face this issue on 1.2 . is there any global
setting that i can use so that uimodules render html as html instead
of htmlstrings ?

Felinx Lee

unread,
Oct 29, 2011, 6:13:49 AM10/29/11
to python-...@googlegroups.com
Set autoescape to None in application settings. 

   "xsrf_cookies": True,
    "autoescape": None,
--
What can change the nature of a man?(Planescape Torment)
----------------------------------------------------------------------------------------
http://feilong.me            Felinx Lee's Blog (Chinese Only)
http://www.zhimaq.com IT Q&A (Chinese Only)
http://poweredsites.org  What powered your sites? PHP, Ruby or Python?

deepu

unread,
Oct 29, 2011, 6:33:31 AM10/29/11
to Tornado Web Server
Did this . And still the problem persists.

using {% autoescape None %}
on individual pages and still the problem persists.



On Oct 29, 3:13 pm, Felinx Lee <felinx....@gmail.com> wrote:
> Set autoescape to None in application settings.
>
>    "xsrf_cookies": True,
>     "autoescape": None,
>
> On Sat, Oct 29, 2011 at 5:45 PM, deepu <deepu.kalidi...@gmail.com> wrote:
> > Hi,
> >    i used to use tornado 1.2 for an app of mine. everything worked
> > well. Now Updated to latest version and changed couple of things in
> > the templates like
>
> > previously {{ module ForumPost() }} to {% module ForumPost() % } etc.
>
> > The issue i am facing is that now the html is being rendered as a
> > string because of which the browser is not parsing the html and
> > renders the entire html as a string.
>
> > I am pretty sure i didn't face this issue on 1.2 . is there any global
> > setting that i can use so that uimodules render html as html instead
> > of htmlstrings ?
>
> --
> What can change the nature of a man?(Planescape Torment)
> --------------------------------------------------------------------------- -------------http://feilong.me           Felinx Lee's Blog (Chinese Only)http://www.zhimaq.comIT Q&A (Chinese Only)http://poweredsites.org What powered your sites? PHP, Ruby or Python?

Peter Bengtsson

unread,
Oct 30, 2011, 6:03:56 PM10/30/11
to python-...@googlegroups.com
What's the problem? If you want it rendered unescaped you correctly use the {% module MyModule() %} syntax. So, if MyModule.render returns "<strong>hi</strong>" and you do
<p>{% module MyModule() %}</p> the result becomes "<p><strong>hi</strong></p>". Is that not what you want?

Nhomar Hernández

unread,
Feb 11, 2012, 8:30:12 PM2/11/12
to python-...@googlegroups.com
Hello.

I'm facing exactly the same problem.

But in my case using just a module.

It means:

I made a copy from blog demo.

and it works... to deploy several modules/entry.html in several places...

BUt in my architecture it is not working, Just base template works the "modules" doesn't

What somebody think is happening?

Regards-

2011/10/29 deepu <deepu.k...@gmail.com>



--
--------------------
Saludos Cordiales

Nhomar G. Hernandez M.
+58-414-4110269
Skype: nhomar00
Web-Blog: http://geronimo.com.ve
Servicios IT: http://openerp.com.ve
Linux-Counter: 467724
Correos:
nho...@openerp.com.ve
nho...@geronimo.com.ve
twitter @nhomar

Anderson Cardoso

unread,
Feb 11, 2012, 9:23:22 PM2/11/12
to python-...@googlegroups.com
If I'm not wrong now the templates are escaped automatically.
If you want to remove this behavior you can do:
{% autoescape None %}


2012/2/11 Nhomar Hernández <nho...@openerp.com.ve>



--
Anderson Pierre Cardoso
Computer Engineer - University of Sao Paulo

[gtalk]: apierre...@gmail.com
[blog]:  http://anderson-hacklife.blogspot.com/


"FreeSoftware -> free as in freedom"
  |  mande-me documentos em formatos livres (ODF) -> http://www.infowester.com/odf.php

Nhomar Hernández

unread,
Feb 11, 2012, 9:43:46 PM2/11/12
to python-...@googlegroups.com
Thanks anderson

Where do i put this at the end of the .html file?

Can i use it just one time in some place?

I have home base and.... my news files where is the correct place?

Im pretty new with template management systems ;-)

But i will try! and inform all.

2012/2/11 Anderson Cardoso <apierre...@gmail.com>

Anderson Cardoso

unread,
Feb 11, 2012, 10:03:22 PM2/11/12
to python-...@googlegroups.com
this would go on the top of you html and it would change the behavior of the whole template.
If you want a one time only method you can use the tornado.escape.xhtml_unescape() (there is a xhtml_escape() either)
http://www.tornadoweb.org/documentation/escape.html

pass it to your template, like:
 self.render('my_template.html, some_html_data=data, unescape=tornado.espace.xhtml_unescape)  #this in your handler

on the template:
  {{ unescape( some_html_data) }}

I have not tried, but I think it should work
att

Anderson

OBS: I dont know if this is the better way, but I always use the template with {% autoescape none %} , and when I want something escaped (like user entries or so) I use xhtml_escape method. It works well.

2012/2/12 Nhomar Hernández <nho...@openerp.com.ve>

wataka

unread,
Feb 12, 2012, 5:34:31 AM2/12/12
to Tornado Web Server
You can do it individually for certain variables instead of globally
as in:

{% raw foo_variable %} instead of {{ foo_variable }}



On Feb 12, 4:03 am, Anderson Cardoso <apierre.card...@gmail.com>
wrote:
> this would go on the top of you html and it would change the behavior of
> the whole template.
> If you want a one time only method you can use the
> tornado.escape.xhtml_unescape() (there is a xhtml_escape() either)http://www.tornadoweb.org/documentation/escape.html
>
> pass it to your template, like:
>  self.render('my_template.html, some_html_data=data,
> unescape=tornado.espace.xhtml_unescape)  #this in your handler
>
> on the template:
>   {{ unescape( some_html_data) }}
>
> I have not tried, but I think it should work
> att
>
> Anderson
>
> OBS: I dont know if this is the better way, but I always use the template
> with {% autoescape none %} , and when I want something escaped (like user
> entries or so) I use xhtml_escape method. It works well.
>
> 2012/2/12 Nhomar Hernández <nho...@openerp.com.ve>
>
>
>
>
>
>
>
>
>
> > Thanks anderson
>
> > Where do i put this at the end of the .html file?
>
> > Can i use it just one time in some place?
>
> > I have home base and.... my news files where is the correct place?
>
> > Im pretty new with template management systems ;-)
>
> > But i will try! and inform all.
>
> > 2012/2/11 Anderson Cardoso <apierre.card...@gmail.com>
>
> >> If I'm not wrong now the templates are escaped automatically.
> >> If you want to remove this behavior you can do:
> >> {% autoescape None %}
>
> >> 2012/2/11 Nhomar Hernández <nho...@openerp.com.ve>
>
> >>> Hello.
>
> >>> I'm facing exactly the same problem.
>
> >>> But in my case using just a module.
>
> >>> It means:
>
> >>> I made a copy from blog demo.
>
> >>> and it works... to deploy several modules/entry.html in several places...
>
> >>> BUt in my architecture it is not working, Just base template works the
> >>> "modules" doesn't
>
> >>> What somebody think is happening?
>
> >>> Regards-
>
> >>> 2011/10/29 deepu <deepu.kalidi...@gmail.com>
> >> [gtalk]: apierre.card...@gmail.com
> >> [blog]:  http://anderson-hacklife.blogspot.com/
>
> >> "FreeSoftware -> free as in freedom"  |  mande-me documentos em formatos
> >> livres (ODF) ->http://www.infowester.com/odf.php
>
> > --
> > --------------------
> > Saludos Cordiales
>
> > Nhomar G. Hernandez M.
> > +58-414-4110269
> > Skype: nhomar00
> > Web-Blog:http://geronimo.com.ve
> > Servicios IT:http://openerp.com.ve
> > Linux-Counter: 467724
> > Correos:
> > nho...@openerp.com.ve
> > nho...@geronimo.com.ve
> > twitter @nhomar
>
> --
> Anderson Pierre Cardoso
> Computer Engineer - University of Sao Paulo
>
> [gtalk]: apierre.card...@gmail.com

Nhomar Hernández

unread,
Feb 12, 2012, 8:19:28 AM2/12/12
to python-...@googlegroups.com
Hello.

Just for records:

Putting the method on my base template:

{% autoescape None %}

This method doesn't do anything if yu put directly on a ui_module (Where i had the problem.)
I don't know if this is a bug or something.

The problem was the BOM of my file, i have servers on Canada installed with en_CA and it is a little different, when i create my files with vim on this servers the encoding was setted to one wrong.

I develop a little module that allow to you compare BOM for several files in the same directory.

You can download from Launchpad.

bzr push lp:~nhomar/+junk/encoding_files

Thanks a lot, this problem take me at leat 8 hours :-(

2012/2/12 wataka <nhy...@googlemail.com>

Nhomar Hernández

unread,
Feb 12, 2012, 8:24:03 AM2/12/12
to python-...@googlegroups.com
El 12 de febrero de 2012 08:49, Nhomar Hernández <nho...@openerp.com.ve> escribió:
Hello.

Just for records:

Putting the method on my base template:

It solved my problem (I didn't say explicit)  Thanks friends.
Reply all
Reply to author
Forward
0 new messages