您使用的是webapp2框架嗎?
如果是這樣,請繼續閱讀...
您需要四個文件。爲簡單起見,所有位於您的應用程序的根文件夾:
app.yaml
urls.py
SampleController.py
Sample.html
您的app.yaml,你應該有這樣的事情:
handlers:
- url: /.*
script: urls.ap
這告訴AppEngine上路由所有網址模式urls.py.
然後在你的urls.py,你有這樣的結構:
import webapp2
import SampleController
#For each new url structure, add it to router.
#The structure is [py filename].[class name inside py file]
app = webapp2.WSGIApplication(debug=True)
app.router.add((r'/', SampleController.SampleHandler))
def main():
application.run()
if __name__ == "__main__":
main()
在你的問題,你有三種結構:/,/ problem2,/ problem3。他們會對應這些:
app.router.add((r'/', SampleController.SampleHandler))
app.router.add((r'/problem2', SampleController.SampleHandler2))
app.router.add((r'/problem3', SampleController.SampleHandler3))
這取決於你決定是否他們去同一個處理程序或不。
SampleController.py看起來是這樣的:
import webapp2
import os
class SampleHandler(webapp2.RequestHandler):
def get(self):
template_values = {
'handler': 'We are in SampleHandler',
'param2': param2
}
path = os.path.join(os.path.dirname(__file__), 'Sample.html')
self.response.out.write(template.render(path, template_values))
class SampleHandler2(webapp2.RequestHandler):
def get(self):
template_values = {
'handler': 'We are in SampleHandler2',
'param2': param2
}
path = os.path.join(os.path.dirname(__file__), 'Sample.html')
self.response.out.write(template.render(path, template_values))
class SampleHandler3(webapp2.RequestHandler):
def get(self):
template_values = {
'handler': 'We are in SampleHandler3',
'param2': param2
}
path = os.path.join(os.path.dirname(__file__), 'Sample.html')
self.response.out.write(template.render(path, template_values))
通知他們都去同一個Sample.html文件。
Sample.html只是標準的html代碼。
與論壇網站不同,我們不使用「謝謝」,或「任何幫助表示讚賞」,或在[so]上簽名。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be -removed-from-posts) –
是的,它是可行的,查看[Documentation](https://developers.google.com/appengine/docs/python/config/appconfig)。當你嘗試一些東西時,來返回並編輯您的問題以顯示您的嘗試(如果您有任何課程上的困難,goodluck) –