如何发送删除请求到python服务器

问题描述:

我正在应用程序的前端工作。我需要从html模板发送删除请求到服务器。删除功能的工作原理如下:如何发送删除请求到python服务器

def do_DELETE(self): 
     if re.match(r'\/product\/\d+', self.path): # match "/product/{ID}" 
      #send response code: 
      self.send_response(200) 
      #send headers: 
      self.send_header("Content-type:", "application/json") 
      # send a blank line to end headers: 
      self.wfile.write("\n") 
      #send response: 
      db.delete(re.search(r'[^/]*$', self.path).group(0)), self.wfile 
      return 

我明白URL请求会,说,/product/2。不过,我更熟悉节点的风格,例如:

<form id="delete-form" action="product/<%= product._id %>?_method=DELETE" method="POST"> 
    <input type="submit" value="Delete"> 
</form> 

我无法找到他们的方式在发送请求到服务器蟒蛇时,这将被处理。

我该如何发送一个url到python服务器中的删除请求?

您需要向服务器发送HTTP DELETE请求。您正在发出POST请求,并且您有一个DELETE处理程序。

您应该使用JavaScript来创建DELETE请求。

function reqListener() { 
    console.log(this.responseText); 
} 

var oReq = new XMLHttpRequest(); 
oReq.addEventListener("load", reqListener); 
oReq.open("DELETE", "/product/2"); 
oReq.send();