Using the Google App Store guestbook demo as an example, when entering a entry over multiple lines and storing it, when read back and displayed it appears on one single line.
How can we make it appear excactly as it was originally entered, over multiple lines?
The databasemodel is like this:
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
And the submission form is like this:
self.response.out.write("""
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
Html ignores EOL special characters like \r\n
or \n
.
Here are some options:
Replace the special characters with the proper html <br>
tag
Wrap the multiline text inside a <pre>
tag
In case you are using webapp templating, try with {{greeting.content|linebreaks}}
as suggested by @wooble
Set white-space:pre
in your CSS as suggested by @Nick (example here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With