2010-08-02 125 views
1

我工作的一个项目,我需要使用多个HTML页面与我的代码 喜欢互动: 查看index.html的第一: -渲染multipe 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)) 

的问题是程序在同一时间观看两个页面在一起,这不是我想要的。

你能PLZ告诉我怎样才能查看它们seperately

回答

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将这两个URL映射到你的.py文件。