Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Datastore multiline entries not displayed as multiline in HTML

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>""")
like image 760
Pedro Avatar asked Feb 25 '23 12:02

Pedro


1 Answers

Html ignores EOL special characters like \r\n or \n.

Here are some options:

  1. Replace the special characters with the proper html <br> tag

  2. Wrap the multiline text inside a <pre> tag

  3. In case you are using webapp templating, try with {{greeting.content|linebreaks}} as suggested by @wooble

  4. Set white-space:pre in your CSS as suggested by @Nick (example here)

like image 154
systempuntoout Avatar answered May 06 '23 08:05

systempuntoout