What is the method of doing nl2br in Genshi?

2020-08-01 05:40发布

hiyas. I using Genshi+Pylons.

please teach me, how use \n to <br/>tag in Genshi?

I hope to obtain the same result as "nl2br" in php to change line.
Or, does not the solution exist?

i'm assign template to some text.

(genshi template)
<p>${c.message}</p>

Im tried. case 1:

(python code)
c.message = """
foo
bar
"""

NG. display result is "foo bar"

case 2:

(python code)
c.message = """
foo<br />
bar

"""

NG. display result is "foo<br />bar".
displayed escaped stirings!
It was a same deal as <br/> as for <br />.

Postscript.
I want to avoid using the pre tag.

thanks.
When it is not easy to read because it is not good, I'm sorry by English.

1条回答
Root(大扎)
2楼-- · 2020-08-01 06:20

Try this:

<py:for each="line in message.split('\n')">${line}<br /></py:for>
查看更多
登录 后发表回答