Python Google App Engine数据存储多行条目在HTML中不显示为多行

Python Google App Engine数据存储多行条目在HTML中不显示为多行,python,google-app-engine,multiline,Python,Google App Engine,Multiline,以Google App Store留言簿演示为例,在多行输入条目并存储时,在回读并显示时,它会显示在一行上。 我们如何才能使它在多行中显示为最初输入的样子 数据库模型如下所示: class Greeting(db.Model): author = db.UserProperty() content = db.StringProperty(multiline=True) date = db.DateTimeProperty(auto_now_add=True) self.

以Google App Store留言簿演示为例,在多行输入条目并存储时,在回读并显示时,它会显示在一行上。
我们如何才能使它在多行中显示为最初输入的样子

数据库模型如下所示:

class Greeting(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
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>""")
提交表格如下:

class Greeting(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
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>""")
self.response.out.write(“”)
""")

Html忽略EOL特殊字符,如
\r\n
\n

以下是一些选项:

  • 用正确的html

    标记替换特殊字符

  • 将多行文本包装在
    标记内

  • 如果您正在使用webapp模板,请按照@wooble的建议尝试使用
    {{{greeting.content | linebreaks}}

  • 按照@Nick的建议在CSS中设置
    空白:pre
    (示例)


  • 如果您使用的是模板,(1)可能与在模板中添加过滤器一样简单;在django(这是webapp模板使用的)中,对正在使用的元素在CSS上设置“whitespace:pre”。