google app engine _method? put(self):

K

kristiannissen

How can I get the request passed on to my views when using this
middleware?

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

def __call__(self, environ, start_response):
request = Request(environ)
body = StringIO.StringIO(request.body)

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

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

return self.app(environ, start_response)

when i test :

class Spot(webapp.RequestHandler):
def put(self):
logging.info("hello from put %s", self.request.get("author"))

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

and this is the form:

<form method="post" action="/spot/new/">
<input type="hidden" name="_method" value="put" />
<input type="text" name="name" value="" />
<input type="submit" value="Save" />
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top