所以在這裡把一些東西記錄起來.
在app.yaml中, 把handlers改寫成下面的樣子
handlers:
- url: /controller1/.*
script: controller1.py # 這是http://xxx.com/controller1/
- url: /controller2/.*
script: controller2.py # 這是http://xxx.com/controller2/
- url: /.*
script: main.py # 這是http://xxx.com/
然後建立controller1.py與controller2.py.
然後內容照下面打, 遇到controller1, 在按照檔案打上
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('controller2')
class action(webapp.RequestHandler):
def get(self, aaa):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('controller1.test')
application = webapp.WSGIApplication([
('/controller1/action/(.*)', action), # 這是http://xxx.com/controller1/action/
('/controller1/', MainPage) # 這是http://xxx.com/controller1/
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
這樣就可以了!!
沒有留言:
張貼留言