我正在将 GAE 数据存储与 python 一起使用,我想计算并显示两个最近日期之间的记录数。例如,数据存储中有多少条记录在两分钟前和三分钟前之间具有时间签名。谢谢你。
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from datetime import datetime
class Voice(db.Model):
when = db.DateTimeProperty(auto_now_add=True)
class MyHandler(webapp.RequestHandler):
def get(self):
voices = db.GqlQuery(
'SELECT * FROM Voice '
'ORDER BY when DESC')
values = {
'voices': voices
}
self.response.out.write(template.render('main.html', values))
def post(self):
voice = Voice()
voice.put()
self.redirect('/')
self.response.out.write('posted!')
def main():
app = webapp.WSGIApplication([
(r'.*', MyHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == "__main__":
main()