0

我有一个 html 页面,您可以在其中在表单中输入信息,当您单击提交按钮时,它会重定向页面并使用新信息更新表格。我使用了“self.redirect('/')”,它确实重新加载了所有内容,但没有更新表格,除非我手动刷新页面。下面是我的代码:

#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('/')

我在这里做错了吗?

4

1 回答 1

0

这是因为数据存储的最终一致性。添加到数据存储区的项目可能需要一段时间才能对不直接使用其密钥的查询可见。MyGames.query()在你的情况下。

于 2015-10-12T15:40:21.670 回答