如何配置app.yaml以支持/ user / <user-id>?</user-id>等网址

时间:2011-04-23 09:31:09

标签: python google-app-engine

我做以下

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

以及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)

看起来有些不对劲。

1 个答案:

答案 0 :(得分:5)

app.yaml中,您想要执行以下操作:

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

然后在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()