我主要關注瞭如何使用GAE和Python構建gustbook的教程。現在我只想顯示從某一天的條目,但GQL查詢不返回任何東西(雖然有從那天項):爲什麼我的GQL查詢不會在我的GAE應用程序中返回任何結果?
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 %}
+1。或者,您可以將DateProperty添加到模型中,然後使用相等過濾器來查詢。這會佔用更多的空間,但會更容易查詢(等於二等關係運算符 - 特別重要,因爲您只能在一個字段上使用關係運算符)。 – 2010-11-05 20:01:38
謝謝你補充說,大衛。 – bernie 2010-11-05 20:03:27
謝謝,它現在正在工作。是否因爲一些「四捨五入」的問題,我不能只使用'='? – weiqure 2010-11-05 20:11:27