Discussion:
How to transfer a string with html tags
DongInn Kim
2010-10-28 21:02:37 UTC
Permalink
Hi,

I am still playing with the genshi tutorial codes and I tried to transfer a string with some html tags through template.render(string).

But the render just transforms my html tags to the mapped format tags. (e.g., <b> --> &lt;b&gt; )
So, the transferred string does not show properly on my template.

Is there any way to transfer a string with html tag without actually converting my html tags?

Regards,
--
- DongInn
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
James Mills
2010-10-28 23:05:36 UTC
Permalink
Post by DongInn Kim
Is there any way to transfer a string with html tag without actually converting my html tags?
Use the Markup class.

cheers
James
--
-- James Mills
--
-- "Problems are solved by method"
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
DongInn Kim
2010-10-29 14:14:27 UTC
Permalink
Thanks James for your kind answer. It helped to solve the question.
But I would like to make sure that my solution is correct.

So what I did is.

from genshi.core import Markup

@cherrypy.expose
@template.output('index.html')
def index(self):
return Markup(template.render(string)).unescape()

Do you have any concerns or problems of doing this?

Actually all I wanted is just unescape the "string" and then put template.render(string) but it did not work because it seems that html tag escaping stuff is done inside of template.render.

Regards,
Post by James Mills
Post by DongInn Kim
Is there any way to transfer a string with html tag without actually converting my html tags?
Use the Markup class.
cheers
James
--
- DongInn
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
kylealanhale
2010-10-29 19:22:20 UTC
Permalink
Either I'm misunderstanding what you're trying to do, or you are
misunderstanding the purpose of the tutorial's template.output and
template.render. Those two decorators are for rendering a genshi
template stored in a file somewhere. This:

return Markup(template.render(string)).unescape()
Post by DongInn Kim
Post by James Mills
html_string = u'<b>hey</b>'
html_string == Markup(html_string).unescape()
True

Also, you don't pass a string to template.render (unless it's the path
to a template file), you pass it keyword arguments that define the
context inside the rendered template.

So, if you just want to return an HTML string via a CherryPy endpoint,
just return the string as is. If you're trying to pass in an HTML
string to a template, then call

template.render(html_markup=Markup(html_string))

and then within your template access the markup with

${html_markup}
Post by DongInn Kim
Thanks James for your kind answer. It helped to solve the question.
But I would like to make sure that my solution is correct.
So what I did is.
from genshi.core import Markup
        return Markup(template.render(string)).unescape()
Do you have any concerns or problems of doing this?
Actually all I wanted is just unescape the "string" and then put template.render(string) but it did not work because it seems that html tag escaping stuff is done inside of template.render.
Regards,
Post by James Mills
Is there any way to transfer a string with html tag without actually converting my html tags?
Use the Markup class.
cheers
James
--
- DongInn
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
DongInn Kim
2010-10-29 20:39:56 UTC
Permalink
Hi Kylealanhale,

Yes, your answer is exactly what I was looking for. Thank you very much.

Regards,
Post by kylealanhale
Either I'm misunderstanding what you're trying to do, or you are
misunderstanding the purpose of the tutorial's template.output and
template.render. Those two decorators are for rendering a genshi
return Markup(template.render(string)).unescape()
Post by DongInn Kim
Post by James Mills
html_string = u'<b>hey</b>'
html_string == Markup(html_string).unescape()
True
Also, you don't pass a string to template.render (unless it's the path
to a template file), you pass it keyword arguments that define the
context inside the rendered template.
So, if you just want to return an HTML string via a CherryPy endpoint,
just return the string as is. If you're trying to pass in an HTML
string to a template, then call
template.render(html_markup=Markup(html_string))
and then within your template access the markup with
${html_markup}
Post by DongInn Kim
Thanks James for your kind answer. It helped to solve the question.
But I would like to make sure that my solution is correct.
So what I did is.
from genshi.core import Markup
@cherrypy.expose
@template.output('index.html')
return Markup(template.render(string)).unescape()
Do you have any concerns or problems of doing this?
Actually all I wanted is just unescape the "string" and then put template.render(string) but it did not work because it seems that html tag escaping stuff is done inside of template.render.
Regards,
Post by James Mills
Is there any way to transfer a string with html tag without actually converting my html tags?
Use the Markup class.
cheers
James
--
- DongInn
--
- DongInn
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to genshi+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/genshi?hl=en.
Continue reading on narkive:
Loading...