2013-08-31 1 views
1

다음 경로를 설정하고 rest API를/rest와 일치시킵니다.특정 경로가 일치 할 때 404를 표시합니다.

routes = [ 
    PathPrefixRoute('/rest', [ 
     Route('/customers', handler='app.handlers.CustomerHandler:list', 
          methods=['GET']), 
     # some other /rest routers 
     Route('/<:.*>', ?) # this route should execute abort(404) 
    ]), 
    Route('/<page:.*>', handler='app.handlers.PageHandler', methods=['GET']) 
] 

누군가가 내가 404

보여주고 싶은 /rest/does_not_exists URL이 경로에서 중단 (404)를 호출 할 수있는 방법이 있나요 아니면 내가 그 핸들러를 작성해야 액세스하는 경우?

답변

0

모든 경로 단지 페이지와 같은 이것이 마지막 질문의와 같은 컨텍스트에있는 경우

if not os.path.exists(os.path.join(template_path, page)): 
    self.abort(404) 

을 할 수 있지만, 그래 당신이 특정에 self.abort를 호출하는 핸들러를 작성해야 캐치를 가지고 있기 때문에 잡히지 않은 경로는 기본적으로 정확하게이 경로를 사용합니다.