diff --git a/django/middleware/common.py b/django/middleware/common.py index 12d006127b..9f71b9d278 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -78,12 +78,12 @@ class CommonMiddleware(MiddlewareMixin): Return the full path of the request with a trailing slash appended. Raise a RuntimeError if settings.DEBUG is True and request.method is - POST, PUT, or PATCH. + DELETE, POST, PUT, or PATCH. """ new_path = request.get_full_path(force_append_slash=True) # Prevent construction of scheme relative urls. new_path = escape_leading_slashes(new_path) - if settings.DEBUG and request.method in ("POST", "PUT", "PATCH"): + if settings.DEBUG and request.method in ("DELETE", "POST", "PUT", "PATCH"): raise RuntimeError( "You called this URL via %(method)s, but the URL doesn't end " "in a slash and you have APPEND_SLASH set. Django can't " diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index 2153a0bb5a..4dc1c83c42 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -107,11 +107,11 @@ class CommonMiddlewareTest(SimpleTestCase): self.assertEqual(resp.url, "/slash/?test=slash/") @override_settings(APPEND_SLASH=True, DEBUG=True) - def test_append_slash_no_redirect_on_POST_in_DEBUG(self): + def test_append_slash_no_redirect_in_DEBUG(self): """ While in debug mode, an exception is raised with a warning - when a failed attempt is made to POST, PUT, or PATCH to an URL which - would normally be redirected to a slashed version. + when a failed attempt is made to DELETE, POST, PUT, or PATCH to an URL + which would normally be redirected to a slashed version. """ msg = "maintaining %s data. Change your form to point to testserver/slash/" request = self.rf.get("/slash") @@ -126,6 +126,9 @@ class CommonMiddlewareTest(SimpleTestCase): request.method = "PATCH" with self.assertRaisesMessage(RuntimeError, msg % request.method): CommonMiddleware(get_response_404)(request) + request = self.rf.delete("/slash") + with self.assertRaisesMessage(RuntimeError, msg % request.method): + CommonMiddleware(get_response_404)(request) @override_settings(APPEND_SLASH=False) def test_append_slash_disabled(self):