Google App Engine 数据存储区多行条目未在 HTML 中显示为多行
以 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Html 忽略 EOL 特殊字符,例如
\r\n
或\n
。以下是一些选项:
将特殊字符替换为正确的 html
标记将多行文本包含在
{{greeting.content|linebreaks}}
按照建议在 CSS 中设置
white-space:pre
@Nick(例如此处)Html ignores EOL special characters like
\r\n
or\n
.Here are some options:
Replace the special characters with the proper html
<br>
tagWrap the multiline text inside a
<pre>
tagIn case you are using webapp templating, try with
{{greeting.content|linebreaks}}
as suggested by @woobleSet
white-space:pre
in your CSS as suggested by @Nick (example here)