我有一个html页面,您可以在表单中输入信息,当您单击submit按钮时,它会重定向页面并用新信息更新表。我用过”自我重定向('/')”并且它确实重新加载了所有内容,但不更新表,除非我手动刷新页面。以下是我的代码:
#Used to load up index.html
class MainHandler(webapp2.RequestHandler):
#HTML Get request to pull information from the datastore
def get(self):
title = "Video Game History"
template_vars = {
'title' : title, 'message' : "Enter the video game that you've played before..." }
template = JINJA_ENVIRONMENT.get_template('index.html')
self.response.out.write(template.render(template_vars))
#Pulls info from the datastore and displays it
self.query = MyGames.query()
self.response.write("""
<table>
<caption>Game History</caption>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Company</th>
<th>Console</th>
<th>Genre</th>
<th>Recommend</th>
</tr>
</thead>
<tbody>
""")
for dbInfo in self.query:
self.response.write("""
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
""" % (dbInfo.name, dbInfo.description, dbInfo.company, dbInfo.console, dbInfo.genre, dbInfo.recommend))
self.response.write("""
</tbody>
</table>
""")
#self.response.write('<p>%s</p>' % dbInfo.name)
def post(self):
gameName = self.request.get("gameName")
gameDescription = self.request.get("gameDescription")
gameCompany = self.request.get("company")
gameConsole = self.request.get("console")
gameGenre = self.request.get("genre")
gameRecommend = self.request.get("recommend")
#If gameRecommend is checked, mark yes. Otherwise, mark no.
if gameRecommend == "Recommended":
gameRecommend = "Yes"
else:
gameRecommend = "No"
#Post the information into the datastore
myGames = MyGames(
name = gameName,
description = gameDescription,
company = gameCompany,
console = gameConsole,
genre = gameGenre,
recommend = gameRecommend)
myGames.put()
self.redirect('/')
是不是我做错了什么?在
这是因为数据存储的Eventual Consistency。添加到数据存储中的项可能需要一段时间左右,然后才能对未直接使用其键的查询可见。
MyGames.query()
在你的情况下。在相关问题 更多 >
编程相关推荐