I’m using web.py to generate HTML pages using templates.
The HTML template is like this:
$def with (scene)
...
<p id="descriptions">
$scene.descriptions[scene.status]
</p>
Some of the strings I want it to put there from the descriptions file include line breaks like this:
example_scene = (
"""Status 1 - Line 1
Status 1 - Line 2
Status 1 - Line 3""",
"""Status 2 - Line 1
Status 2 - Line 2
Status 2 - Line 3""",
)
But when it generates the HTML page, those lines are run together like this:
Status 1 – Line 1Status 1 – Line 2Status 1 – Line 3
Rather than like this:
Status 1 – Line 1
Status 1 – Line 2
Status 1 – Line 3
If I include a \n for a Python newline it has no effect, and if I include a <br /> for an HTML newline it simply includes those characters like this:
Status 1 – Line 1<br />Status 1 – Line 2<br />Status 1 – Line 3
Is there any way to preserve those line breaks??
Web.py is escaping the HTML. To turn it off, change your template code: