Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use HTTP method DELETE on Google App Engine?

I can use this verb in the Python Windows SDK. But not in production. Why? What am I doing wrong?

The error message includes (only seen via firebug or fiddler)

Malformed request

or something like that

My code looks like:

from google.appengine.ext import db
from google.appengine.ext import webapp

class Handler(webapp.RequestHandler):
   def delete(self):
       key = self.request.get('key')
       item = db.get(key)
       item.delete()
       self.response.out.write(key)
like image 790
Jader Dias Avatar asked Mar 07 '10 21:03

Jader Dias


1 Answers

Your handler looks OK, are you sure you're sending the request correctly? Using jQuery, this works for me (both using dev_appserver and google app engine production):

$('#delete-button').click(function() {
    $.ajax({
        'type': 'DELETE',
        'url': '/some/url/that/handles/delete'
    })
});

class DeleteHandler(webapp.RequestHandler):

    def delete(self):
        if users.get_current_user() == allowed_user:
            the_data_model.delete()
        else:
            self.response.out.write('Permission denied')

Sending a response body/message did not work for me (e.g. the "permission denied" message in my example won't get to the client). Have you verified your items aren't deleted?

like image 137
pthulin Avatar answered Oct 07 '22 21:10

pthulin