【发布时间】:2011-08-29 16:21:00
【问题描述】:
我正在做一个服务器,可以让客户端上传和下载不同模型的数据。是否有一些优雅的方式来处理请求?
更准确地说,我不想做这样的事情,
app = webapp.WSGIApplication([
('/my_upload_and_download_url/ModelA/(.*)', MyRequestHandlerForA),
('/my_upload_and_download_url/ModelB/(.*)', MyRequestHandlerForB),
('/my_upload_and_download_url/ModelC/(.*)', MyRequestHandlerForC),
])
run_wsgi_app(app)
因为我在处理程序中所做的一切都是一样的。例如,
class MyRequestHandlerForX(webapp.RequestHandler):
def get(self, key=None):
# return the instance with the designated key
def post(self, key=None):
# create/get the model instance
# iterate through the property list of the instance and set the values
处理程序之间的唯一区别是为不同的模型创建实例。 url 是一样的,handler 也差不多。
我检查了this post 关于重定向请求到其他处理程序的信息,并且我还阅读了一些通过类名创建实例的方法;但我认为它们都不好。
谁有好的解决方案?
附言这是我在此的头一篇博文。如果有什么不妥的地方请告诉我,谢谢。
【问题讨论】:
标签: python google-app-engine web-applications