0

다른 URL을 다른 python 스크립트에 매핑하려고합니다. 내가 http://myapp.appspot.com/test에 가면 gae & python - yaml에 다른 URL 설정 : 404 찾을 수 없음

내 YAML

application: myApp 
version: 99 
runtime: python27 
api_version: 1 
threadsafe: yes 

handlers: 
- url: /favicon\.ico 
    static_files: favicon.ico 
    upload: favicon\.ico 

- url: /deleteCustomers 
    script: test.app 

- url: /.* 
    script: main.app 

libraries: 
- name: webapp2 
    version: "2.5.2" 

builtins: 
- remote_api: on 

, 그것은

내가 http://myapp.appspot.com에 가면 오른쪽 스크립트가 실행됩니다 (main.app) ... "404 찾을 수 없습니다"라는

여기에 내가 가지고있는 동일한 문제입니다 ->HERE 하지만 주어진 솔루션은 나를 위해 작동하지 않습니다 (이 같은 코드의 경우에도!)

여기 (이하 "이 경로 YAML"를 테스트하는 핸들러입니다,고객 및 저장소 클래스와 mainhandler를 보유하고있는 main.app를 test.app로 이름을 바꾸어 복제했습니다.

http://www.myapp.appspot.com/deleteCustomershttp://www.myapp.appspot.com/deleteStores

감사를 들어 : 그래서 main.app 및 test.app 모두 내가 두 개의 별도의 전화로 고객과 상점 삭제를 분할 달성하고 싶은 무엇

class MainHandler(webapp2.RequestHandler): 
    def get(self): 
     customers = Customers.all() 
     stores = Stores.all() 

     countCustomers= 0 
     countStores= 0 

     for p in customers: 
      p.delete() 
      countCustomers+= 1 
     for p in stores: 
      p.delete() 
      countStores+= 1 

     self.response.out.write("\nDeleted Customers: " + str(countCustomers)) 
     self.response.out.write("\nDeleted Stores: " + str(countStores)) 

app = webapp2.WSGIApplication([ 
    ('/', MainHandler) 
], debug=True) 

)과 동일하다 모든 도움을 미리, 최고의 안부

+0

시도해보십시오. url : /test.* 또한 처리기와 라우터를 테스트 처리기에 게시 할 수 있습니까? – Tkingovr

+0

작동하지 않습니다. | – BeNdErR

+2

테스트 앱에 코드를 게시 할 수 있습니까? – Tkingovr

답변

1

당신이 말하는 경우 똑같은 다음 당신의 MainHandler를 가리 키도록 동일한 '/'를 사용하고 있다고 가정합니다. 나는 당신을 정확하게 이해하지만, 이것은 당신을 도우려는 나의 시도입니다.

class StoreDeletionHandler(webapp2.RequestHandler): 
def get(self): 
    stores = Stores.all() 

    countStores= 0 

    for p in stores: 
     p.delete() 
     countStores+= 1 

    self.response.out.write("\nDeleted Stores: " + str(countStores))   


app = webapp2.WSGIApplication([('/deleteStores', StoreDeletionHandler)], debug=True) 

위의 라우팅 당신의 main.py 스크립트에있을 것입니다 : 2 개의 다른 스크립트로 저장 삭제 및 고객의 삭제를 분할 달성하기 위해 당신과 같은 각 URL 뭔가에 매핑이 다른 처리기에 코드를 분리해야

- url: /.* 
    script: main.app 

하고이 경우 다른 스크립트 test.py에서 두 번째 URL에 대한 :

class CustomerDeletionHandler(webapp2.RequestHandler): 
    def get(self): 

     customers = Customers.all() 
     countCustomers= 0 

     for p in customers: 
      p.delete() 
      countcustomers+= 1 

     self.response.out.write("\nDeleted Customers: " + str(countCustomers)) 

app = webapp2.WSGIApplication([ 
('/deleteCustomers', CustomerDeletionHandler) 
], debug=True) 

YAML 스크립트에서 다음 호출로 당신의 YAML 파일에서 당신은을 통해 스크립트에 URL을 매핑 할 다음의 URL가 시작해야

- url: /deleteCustomers 
    script: test.app 

또한 test.py 스크립트로 이동하는 모든 후속 경로의 순서 점에 유의 받아 '/ deleteCustomers'접두사이 같은

그래서 뭔가 다음 위의 test.py 스크립트로 이동 것의

http://www.myapp.appspot.com/deleteCustomers/NewUrl1 
http://www.myapp.appspot.com/deleteCustomers/SomethingElse 
http://www.myapp.appspot.com/deleteCustomers/YetAnotherUrlForTestpy 

모든. 아무것도하지만 /의 deleteCustomers에 main.py 스크립트를 사용하면 단순히 경로로 리디렉션

http://www.myapp.appspot.com/ThisGoesToMain 
http://www.myapp.appspot.com/deleteStores #also goes to main 
http://www.myapp.appspot.com/deleteStores/YetAnotherUrlForMain 

나는 이것이 당신이 원하는 무엇인가를 바란다.

+0

감사합니다. Tkingovr, webapp2에서 경로 값을 설정하지 않았습니다.WSGIApplication 함수. 이제 다시 작동합니다. – BeNdErR

관련 문제