【问题标题】:rendering multipe html pages渲染多个 html 页面
【发布时间】:2010-08-02 05:01:52
【问题描述】:

我正在做一个项目,我需要使用多个 html 页面与我的代码进行交互 喜欢: 先查看 index.html:-

 path = os.path.join(os.path.dirname(__file__), 'index.html')
 self.response.out.write(template.render(path, template_values))

然后当我按下退出按钮时,程序应查看此页面:-

path = os.path.join(os.path.dirname(__file__), 'signOut.html')
 self.response.out.write(template.render(path, template_values))

问题是程序同时查看两个页面,这不是我想要的。

你能告诉我如何单独查看它们

【问题讨论】:

    标签: python html google-app-engine


    【解决方案1】:

    你需要这样的东西:

    class MainPage(webapp.RequestHandler):
         def get(self):
             path = os.path.join(os.path.dirname(__file__), 'index.html')   
             self.response.out.write(template.render(path, template_values))
    
    class SignOutPage(webapp.RequestHandler):
         def get(self):
             path = os.path.join(os.path.dirname(__file__), 'signOut.html')   
             self.response.out.write(template.render(path, template_values))
    
    application = webapp.WSGIApplication( 
                                     [('/', MainPage), 
                                      ('/signout', SignOutPage)], 
                                     debug=True) 
    
    def main(): 
        run_wsgi_app(application) 
    
    if __name__ == "__main__": 
        main()
    

    您的两个页面将在http://yourapp.appspot.com/http://yourapp.appspot.com/signout 上提供

    这假设您的 app.yaml 将两个 url 映射到您的 .py 文件。

    【讨论】: