Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use delete() method in Google App Engine Python's request handler

In GAE Python, I could use

class MyRequestHandler(webapp.RequestHandler):
    def get(self):
        pass #Do Something...
    def post(self):
        pass #Do Something...

To handle GET and POST request. But how can I handle DELETE and PUT? I see delete() and put() in API documentation, but I don't know how to write a form to simulate DELETE and PUT.

I know in Rails, I can use post method with a hidden field in form to simulate the requests like this:

<input type="hidden" name="_method" value="delete" />

and Rails handles the dirty works automatically.

Is there any similar way to do it in GAE python?

I searched this in Google, but no luck.

Thanks.

like image 556
venj Avatar asked Sep 18 '10 08:09

venj


People also ask

How do you delete a task in Python?

Deleting tasks from a queueClick the name of the queue from which you want to remove the task. Select the task that you want to delete and click Delete selected tasks. Click Delete.

What is app Engine request handler?

App Engine calls the handler script with a Request and waits for the script to return; all data written to the standard output stream is sent as the HTTP response. There are size limits that apply to the response you generate, and the response may be modified before it is returned to the client.

How does Google handle multiple requests?

Handling requests Any request can be routed to any instance, so consecutive requests from the same user are not necessarily sent to the same instance. An instance can handle multiple requests concurrently. The number of instances can be adjusted automatically as traffic changes.

How long does it take my application to handle a request?

The average length of time it takes to hear back is one to two weeks or around 10-14 days after you submit your application materials. In contrast, certain jobs, like those for government positions could take as long as six to eight weeks to hear back.


2 Answers

You can use the request method which accepts all the methods like get,post,delete and put. Then you can check it for the request type accordingly.

Check this:

http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.urlfetch.html

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

def post(self):
    method= self.request.get("_method")
    if method == 'put':
       #call put() function as required

you can go through this as well for the put specification.

http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html#RequestHandler_put

like image 129
Ankit Jaiswal Avatar answered Sep 22 '22 15:09

Ankit Jaiswal


The HTML specification doesn't allow a form to use the DELETE method, and you probably can't get a browser to send an HTTP DELETE request with a form. The delete() method of a RequestHandler subclass would generally be used for a RESTful web application with a client that knows how to send DELETE requests, rather than using ordinary HTML forms. (For a browser-based client, you can send DELETE requests in javascript using XMLHttpRequest.)

like image 44
Wooble Avatar answered Sep 24 '22 15:09

Wooble