views:

224

answers:

1

Here is a portion of my app.yaml file:

handlers:
- url: /remote_api
  script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
  login: admin
- url: /detail/(\d)+
  script: Detail.py
- url: /.*
  script: Index.py

I want that capture group (the one signified by (\d)) to be available to the script Detail.py. How can I do this?

Do I need to figure out a way to access GET data from Detail.py?

Also, when I navigate to a URL like /fff, which should match the Index.py handler, I just get a blank response.

+2  A: 

I see two questions, how to pass elements of the url path as variables in the handler, and how to get the catch-all to render properly.

Both of these have more to do with the main() method in the handler than the app.yaml

1) to pass the id in the /detail/(\d) url, you want something like this:

class DetailHandler(webapp.RequestHandler):
    def get(self, detail_id):
      # put your code here, detail_id contains the passed variable

def main():
  # Note the wildcard placeholder in the url matcher
  application = webapp.WSGIApplication([('/details/(.*), DetailHandler)]
  wsgiref.handlers.CGIHandler().run(application)

2) to ensure your Index.py catches everything, you want something like this:

class IndexHandler(webapp.RequestHandler):
    def get(self):
      # put your handler code here

def main():
  # Note the wildcard without parens
  application = webapp.WSGIApplication([('/.*, IndexHandler)]
  wsgiref.handlers.CGIHandler().run(application)

Hope that helps.

Jackson Miller
So... you're suggesting that it's better to handle everything from one `.py` file, and parsing URL should be done there and passed to the appropriate functions, but instead of having a separate `.py` file for each different URL path?
Rosarch
You can have multiple handlers if you want, but most apps use a single handler for the bulk of the site. The handler scripts can import other modules to handle individual pages, if they wish.
Nick Johnson
You can have multiple `.py` files or a single. Doesn't really matter. You still have to have the url matchers in the handler (and app.yaml).
Jackson Miller