Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带应用程序引擎和Webapp的Rest Web服务_Python_Google App Engine_Rest_Web Applications - Fatal编程技术网

Python 带应用程序引擎和Webapp的Rest Web服务

Python 带应用程序引擎和Webapp的Rest Web服务,python,google-app-engine,rest,web-applications,Python,Google App Engine,Rest,Web Applications,我想在app engine上构建一个REST web服务。目前我有: from google.appengine.ext import webapp from google.appengine.ext.webapp import util class UsersHandler(webapp.RequestHandler): def get(self, name): self.response.out.write('Hello '+ name+'!') def main():

我想在app engine上构建一个REST web服务。目前我有:

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

class UsersHandler(webapp.RequestHandler):  

def get(self, name):
    self.response.out.write('Hello '+ name+'!') 

def main():
util.run_wsgi_app(application)

#Map url like /rest/users/johnsmith
application = webapp.WSGIApplication([(r'/rest/users/(.*)',UsersHandler)]                                      
                                   debug=True)
if __name__ == '__main__':
    main()
例如,我想在访问path/rest/users时检索我的所有用户。我想我可以通过构建另一个处理程序来实现这一点,但我想知道是否可以在这个处理程序内部实现这一点。

当然,您可以--将处理程序的
get
方法更改为

def get(self, name=None):
    if name is None:
        """deal with the /rest/users case"""
    else:
        # deal with the /rest/users/(.*) case
        self.response.out.write('Hello '+ name+'!') 
以及你的申请

application = webapp.WSGIApplication([(r'/rest/users/(.*)', UsersHandler),
                                      (r'/rest/users', UsersHandler)]                                      
                                     debug=True)

换句话说,将您的处理程序映射到您希望它处理的所有URL模式,并确保处理程序的
get
方法可以很容易地(通常通过其参数)区分它们。

您还可以使用两个处理程序-一个用于“/rest/users/”,另一个用于“/rest/users/(.+)”@Nick,当然,但OP知道,正如他所说的那样“我可以通过构建另一个处理程序来实现这一点,但我想知道是否有可能在这个处理程序内部实现”——因此我没有重复他刚才所说的;-)。可能的重复