views:

55

answers:

0

How can I get the request body passed on to my views?

class RestHTTPMiddleware(object):
  def __init__(self, app):
    self.app = app

  def __call__(self, environ, start_response):
    request = Request(environ)
    environ['wsgi.input'] = StringIO.StringIO(request.body)

    method = webapp.Request(environ).get('_method')

    if method:
      environ['REQUEST_METHOD'] = method.upper()

    return self.app(environ, start_response)

when i test :

def put(self):
    logging.info("spot put %s", self.request.get("name"))

the following is logged: "spot put" but with no value.

this is how it's implemented:

def main():  
  app = webapp.WSGIApplication([
    (r'/spot/new/$', Spot),
    ],
   debug=True)
  # run_wsgi_app(application)
  wsgiref.handlers.CGIHandler().run(RestHTTPMiddleware(app))