How to configure app.yaml to support urls like /us

2019-05-02 13:21发布

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.

1条回答
男人必须洒脱
2楼-- · 2019-05-02 13:38

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()
查看更多
登录 后发表回答