开发者

How to use HTTP method DELETE on Google App Engine?

开发者 https://www.devze.com 2022-12-22 00:27 出处:网络
I can use this verb in the Python Windows SDK. But not in production. Why? What am I doing wrong? The error message in开发者_如何学Pythoncludes (only seen via firebug or fiddler)

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

The error message in开发者_如何学Pythoncludes (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)


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消