How to read back and print text with newlines from a Python (Django) string with HTML?

Posted by user1801486 on Stack Overflow See other posts from Stack Overflow or by user1801486
Published on 2012-11-05T22:22:43Z Indexed on 2012/11/05 23:00 UTC
Read the original article Hit count: 170

Filed under:
|
|
|

If someone types in a phrase, such as:

I see you driving

round town with the girl I love,

and I’m like: haiku.

(no blank lines between each line, but the text is written on three separate lines) into a text box on a web page, and then presses a button which is then stored in a database via Django, and that string is read back and printed on a page, how can I get it to print on an HTML page with the newlines still in the text?

So instead of it being printed back as: I see you driving round town with the girl I love, and I’m like: haiku.

It would print as:

I see you driving

round town with the girl I love,

and I’m like: haiku.

I know that if I use: (textarea)soAndSo.body(/textarea), this preserves the newlines that were in the file when the user typed it up originally. How can I get this same effect, but without having to use textarea boxes?

© Stack Overflow or respective owner

Related posts about python

Related posts about html