Google App Engine multi-line data warehouse records do not appear as multi-line HTML

Using the Google App Store guest book demo as an example, when you write a record on multiple lines and save it, when reading and displaying, one line is displayed.
How can we make it look like it was originally introduced, on several lines?

The database is as follows:

class Greeting(db.Model): author = db.UserProperty() content = db.StringProperty(multiline=True) date = db.DateTimeProperty(auto_now_add=True) 

And the sending form is as follows:

 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>""") 
+4
source share
1 answer

Html ignores special EOL characters such as \r\n or \n .

Here are a few options:

  • Replace special characters with the corresponding html tag <br>

  • Wrap multi-line text inside the <pre>

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

  • Install white-space:pre in your CSS as suggested by @Nick (example here )

+8
source

Source: https://habr.com/ru/post/1347693/


All Articles