Search code examples
pythonhtmlhttpwebapp2

HTTP DELETE with HTML


In webapp2, I've not been able to make an HTTP DELETE request work correctly. As a workaround, I'm using a different URI with GET, but I'd prefer a more RESTful approach.

With this code, the server log shows the DELETE request as a GET request. What am I missing here?

class TeamPages(webapp2.RequestHandler):
    def get(self, team_name):
        ...

    def post(self, team_name):
        ...

    def delete(self, team_name):
        key_name = team_name.upper()
        Team.delete(key_name)
        self.redirect('/teams')

A GET request to /teams/{{ team_name }} responds with a page that includes the following html, but when I submit, it requests the GET method instead of the DELETE method.

<form action="/teams{{ team.team_name }}" method="delete">
    <button type="submit">Delete</button>
</form>

Update

Additional info... I'm developing under Google App Engine and I'm using Chrome on a Mac. Here is the request header that shows GET instead of DELETE...

GET /teams/hornets? HTTP/1.1
Host: localhost:9080
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: dev_appserver_login="test@example.com:True:185804764220139124118"
Referer: http://localhost:9080/teams/hornets
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36

And here is the response header...

HTTP/1.1 405 Method Not Allowed
allow: DELETE
Cache-Control: no-cache
Content-Length: 187
content-type: text/html; charset=UTF-8
Date: Tue, 10 Jun 2014 21:24:36 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Server: Development/2.0

Solution

  • Short answer: The issue is not with the web framework or the browser. This is an HTML limitation. HTML only allows for GET and POST. No other methods are permitted. I've adjusted my title to reflect the subject matter more accurately.

    More details:

    Based on the HTML clue from @Greg, I searched some more. In the comments of a related post, @Guandalino added some great links:

    *Bug report 16071

    *Stack Exchange

    This helps to add some color and arguments for and against the addition of PUT and DELETE to the HTML specification.

    To me (and I'm a newbie), this incompatibility with HTTP does not seem to be congruent with REST principles. I'd think that the mere recognition that so many web frameworks have created workarounds is justification enough for making this standard in a future HTML version.

    Thanks to everyone for the feedback!