2

当我只有在页面的浏览器刷新正确的数据存储内容显示更新GAE数据存储,:GAE数据存储不会刷新

import os 

from google.appengine.ext.webapp import template 
from google.appengine.ext import db 
import webapp2 

#def testkey(): 
# return db.Key.from_path('test', 'test') 

class TestEntity(db.Model): 
    testkey = db.StringProperty(multiline=False) 
    testvalue = db.StringProperty(multiline=False) 

class TestRefreshProblem(webapp2.RequestHandler): 
    def get(self): 
    testquery = TestEntity.all()#.ancestor(testkey()) 
    entities = testquery.run() 
    template_values = { 
     'entities': entities, 
     } 
    path = os.path.join(os.path.dirname(__file__), 'index.html') 
    self.response.out.write(template.render(path, template_values)) 

class TestRefreshProblemPost(webapp2.RequestHandler): 
    def post(self): 
    # testEntity = TestEntity(parent=testkey()) 
    testEntity = TestEntity() 
    testEntity.testkey = self.request.get('testkey') 
    testEntity.testvalue = self.request.get('testvalue') 
    testEntity.put() 
    self.redirect('/') 

app = webapp2.WSGIApplication([ 
    ('/', TestRefreshProblem), 
    ('/pst', TestRefreshProblemPost) 
], debug=True) 

和index.html是:

<html> 
    <body> 
    <table border=0> 
     <tr><td width=200>Key</td><td width=200>Value</td></tr> 
     {% for entity in entities %} 
      <tr> 
      <td width=200>{{ entity.testkey|escape }}</td> 
      <td width=200>{{ entity.testvalue|escape }}</td> 
      </tr> 
     {% endfor %} 
     </table> 
    <form action="/pst" method="post"> 
     <table> 
     <td ><input type="text" name="testkey" size=30/></td> 
     <td ><input type="text" name="testvalue" size=30/></td> 
     <tr><td><input type="submit" value="Add entity"></td></tr> 
     </table> 
    </form> 
    </body> 
</html> 

问题通过使用(虚拟)祖先消失(re:带有#的行)。在我看来,这是一种奇怪的行为......它可以在没有祖先的情况下解决吗?

回答

6

由于eventual consistency,这是预期的行为。

实际上,因为您正在运行开发服务器,所以这只是最终一致性的模拟 - 在实际生产系统中,结果不会像预测一样。解决方案虽然相同。

+0

非常感谢。它现在确实有道理;-) – rimvanvliet