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

发布于 2024-10-31 21:38:27 字数 676 浏览 9 评论 0原文

以 Google 应用商店留言簿演示为例,当在多行中输入一个条目并存储它时,当读回并显示时,它会显示在一行上。
我们怎样才能让它在多行中完全按照最初输入的样子显示?

数据库模型是这样的:

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>""")

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>""")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有一腔孤勇 2024-11-07 21:38:27

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

以下是一些选项:

  1. 将特殊字符替换为正确的 html
    标记

  2. 将多行文本包含在

     标签内

  3. In case 如果您正在使用 Web 应用程序模板,请按照 @wooble 的建议尝试使用 {{greeting.content|linebreaks}}

  4. 按照建议在 CSS 中设置 white-space:pre @Nick(例如此处

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文