我试图从这个google GAE教程视频中移植一个好的老留言簿示例: http://www.youtube.com/watch?gl=DE&hl=de&v=bfgO-LXGpTM
问题:当我通过重定向.self(“/”),页面不会自动重新加载。我需要手动重新加载浏览器窗口(例如通过F5)来查看最新的留言簿条目,这是在MakeGuestbookEntry类中完成的。在
对于python2.5.2+webapp,这个问题不存在。在
这是python代码文件主.py公司名称:
#!/usr/bin/env python
Import OS, says
import wsgiref.handlers
import webapp2
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
class guestbook(db.Model):
message = db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
who = db.StringProperty()
class ShowGuestbookPage(webapp2.RequestHandler):
def get(self):
# Read from the Datastore
shouts = db.GqlQuery('SELECT * FROM guestbook ORDER BY when DESC')
values = {'shouts': shouts}
self.response.out.write(template.render('main.html', values))
class MakeGuestbookEntry(webapp2.RequestHandler):
def post(self):
shout = guestbook(message=self.request.get('message'), who=self.request.get('who'))
# Write into the datastore
shout.put()
self.redirect('/')
app = webapp2.WSGIApplication([('/', ShowGuestbookPage),
('/make_entry', MakeGuestbookEntry),
debug=True)
def main():
run_wsgi_app(app)
if __name__ == "__main__":
main()
这是html页面主.html在
^{pr2}$谢谢你的帮助。 谨致问候
那篇教程很古老。我建议您使用Getting Started guide中最新的留言簿教程。在
这种行为的原因,尤其是如果您在dev服务器中,是因为GAE现在模拟最终一致性。基本上,这意味着你新添加的留言簿条目不会立即出现在你的应用程序正在运行的所有服务器上。有些用户可能会立即看到,有些可能不会。确保你得到最新数据的一个好方法是刷新页面并强制应用程序加载它……但是当然你不能期望用户喜欢这样:P
新的guestbook教程使用祖先查询,这将强制实现强一致性。换言之,用户将立即看到更新,无需刷新页面!您可以阅读更多关于强一致性here。在
相关问题 更多 >
编程相关推荐