我主要关注的是关于如何使用 GAE 和 Python 构建 gustbook 的教程。现在我只想显示特定日期的条目,但 GQL 查询不返回任何内容(尽管有当天的条目):
class Shout(db.Model):
message= db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
who = db.StringProperty()
class MainHandler(webapp.RequestHandler):
def get(self):
shouts = db.GqlQuery("SELECT * FROM Shout WHERE when=DATE('2010-11-05')")
# Return something without the WHERE clause
values = {'shouts':shouts}
self.response.out.write(template.render('main.html',values))
def post(self):
self.response.out.write("posted")
shout = Shout(message=self.request.get("message"),who=self.request.get("who"))
shout.put()
这是我的 main.html:
<form method="post">
<input type="text" name="who"></input>
<input type="text" name="message"></input>
<input type="submit" value="Send"> </input>
</form>
{% for shout in shouts %}
<div>{{shout.message}} from {{shout.who}} on {{shout.when}}</div>
{% endfor %}