google app engine _method? put(self):
kristiannissen
kristian.nissen at gmail.com
Wed Sep 15 03:22:16 EDT 2010
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>
More information about the Python-list
mailing list