当我更新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)
Run Code Online (Sandbox Code Playgroud)
和index.html是:
<html>
<body> …
Run Code Online (Sandbox Code Playgroud) python google-app-engine refresh ancestor google-cloud-datastore