我正在做一个项目,我需要使用多个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))
问题是程序一次查看两个页面,这不是我想要的。
您能告诉我如何分开查看吗
最佳答案
您需要这样的东西:
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文件。