How to use HTTP method DELETE on Google App Engine?

和自甴很熟 提交于 2019-12-21 12:10:41

问题


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)

回答1:


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?



来源:https://stackoverflow.com/questions/2398012/how-to-use-http-method-delete-on-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!