【发布时间】:2011-04-19 02:14:17
【问题描述】:
我在 GAE 上使用 Tornado 框架 (Python)。我对整个 MVC 概念和 GAE 还是有点陌生......并且有一段时间试图弄清楚如何做到这一点。
我有一个表格(模型)帖子,其中包含字段用户、文本、创建日期。
我拉取代码中的所有帖子,然后将其发送到模板。我想格式化 creation_date 字段,使其格式更好一些。像 M-d-Y 这样的东西。我知道我使用 strptime 或 strftime 来格式化 creation_date。但是在将帖子发送到模板之前,我不确定该怎么做。
这是我用来获取帖子并将其发送到模板的内容...
class HomeHandler(BaseHandler):
def get(self):
posts = Post.all()
posts.order("-creation_date")
self.render('home.html', posts=posts)
更新:
posts = Post.all().order("-creation_date").fetch(50)
posts = [{'text': post.text} for post in posts]
for post in posts:
print post.text
我收到的错误消息:
AttributeError: 'dict' 对象没有属性 'text'
【问题讨论】: