Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure app.yaml to support urls like /user/<user-id>?

I do the following

- url: /user/.*
  script: script.py

And the following handling in script.py:

class GetUser(webapp.RequestHandler):
    def get(self):
        logging.info('(GET) Webpage is opened in the browser')
        self.response.out.write('here I should display user-id value')

application = webapp.WSGIApplication(
                                     [('/', GetUser)],
                                     debug=True)

Looks like something is wrong there.

like image 747
LA_ Avatar asked Apr 23 '11 09:04

LA_


1 Answers

In app.yaml you want to do something like:

- url: /user/\d+
  script: script.py

And then in script.py:

class GetUser(webapp.RequestHandler):
    def get(self, user_id):
        logging.info('(GET) Webpage is opened in the browser')
        self.response.out.write(user_id)
        # and maybe you would later do something like this:
        #user_id = int(user_id)
        #user = User.get_by_id(user_id)

url_map = [('/user/(\d+)', GetUser),]
application = webapp.WSGIApplication(url_map, debug=True) # False after testing

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()
like image 90
mechanical_meat Avatar answered Oct 05 '22 22:10

mechanical_meat