技术探索:Google App Engine、Zenoss与Python包管理
1. Google App Engine数据查询与URL路由
在Google App Engine开发中,数据查询和URL路由是常见操作。以下是一段用于从数据存储中获取最后10条记录的代码:
collection = []
#grab last 10 records from datastore
query = ChangeModel.all().order('-date')
records = query.fetch(limit=10)
#formats decimal correctly
for change in records:
collection.append(decimal.Decimal(change.input)/100)
template_values = {
'inputs': collection,
'records': records,
}
path = os.path.join(os.path.dirname(__file__), 'query.html')
self.response.out.write(template.render(path,template_values))
其中,关键的两行代码为:
query = ChangeModel.all().order('-date')
records = query.fetch(limit=10)
这
超级会员免费看
订阅专栏 解锁全文
61

被折叠的 条评论
为什么被折叠?



