fce*_*uti 10 python rest google-app-engine web-applications
我想在app引擎上构建一个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()
Run Code Online (Sandbox Code Playgroud)
我想在访问路径/休息/用户时检索所有用户.我想象我可以通过构建另一个处理程序来做到这一点,但我想知道是否可以在此处理程序中执行此操作.
Ale*_*lli 14
当然,你可以 - 改变你的处理程序的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+'!')
Run Code Online (Sandbox Code Playgroud)
和你的申请
application = webapp.WSGIApplication([(r'/rest/users/(.*)', UsersHandler),
(r'/rest/users', UsersHandler)]
debug=True)
Run Code Online (Sandbox Code Playgroud)
换句话说,将处理程序映射到您希望它处理的所有URL模式,并确保处理程序的get方法可以轻松区分它们(通常通过其参数).
| 归档时间: |
|
| 查看次数: |
2261 次 |
| 最近记录: |