Python GAE数据存储不刷新
当我更新GAE数据存储时,只有在浏览器刷新页面后,才会显示正确的数据存储内容:Python GAE数据存储不刷新,python,google-app-engine,refresh,google-cloud-datastore,ancestor,Python,Google App Engine,Refresh,Google Cloud Datastore,Ancestor,当我更新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
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>
键值
{entities%%中实体的百分比}
{{entity.testkey | escape}
{{entity.testvalue | escape}}
{%endfor%}
通过使用(虚拟)祖先(re:带#的行),问题消失了。在我看来,这是一种奇怪的行为。。。没有祖先可以解决吗?这是预期的行为,因为
实际上,因为您正在运行开发服务器,所以这只是对最终一致性的模拟——在实际的生产系统中,结果将不太可预测。不过解决方案是一样的。非常感谢。现在确实有道理了;-)