本文介绍了如何在Google App Engine上使用HTTP方法DELETE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Python Windows SDK中使用这个动词。但不在生产中。为什么?我在做什么错了?

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)

或类似的内容

我的代码如下所示:

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)


推荐答案

您的处理程序看起来没问题,您确定要正确发送请求吗?使用jQuery,这适用于我(都使用dev_appserver和谷歌应用程序引擎生产):

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?

这篇关于如何在Google App Engine上使用HTTP方法DELETE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:31