渲染多个html页面

时间:2010-08-02 05:01:52

标签: python html google-app-engine

我正在开发一个项目,我需要使用多个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))

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

你可以告诉我如何分别查看它们

1 个答案:

答案 0 :(得分:2)

你需要这样的东西:

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将两个网址都映射到您的.py文件。