呈现多个html页面

2024-04-20 12:32:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,我需要使用多个html页面来与我的代码交互 比如: 查看索引.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))

问题是程序一次同时查看两个页面,这不是我想要的。你知道吗

你能告诉我怎样才能把它们分开看吗


Tags: pathself程序osresponsehtmltemplate页面
1条回答
网友
1楼 · 发布于 2024-04-20 12:32:22

你需要这样的东西:

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上可用

这假设您的附录yaml正在将两个URL映射到.py文件。你知道吗

相关问题 更多 >