From 214d88ce86e6257437bf2702ea6ef60e0ae23fad Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 19 Jun 2006 02:04:37 +0000 Subject: [PATCH] Fixed #1646 -- Added HttpResponseNotAllowed, as suggested by Ian Holsman. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3144 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/http/__init__.py | 6 ++++++ docs/request_response.txt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/django/http/__init__.py b/django/http/__init__.py index bb03ab8ea5..178510c94c 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -265,6 +265,12 @@ class HttpResponseForbidden(HttpResponse): HttpResponse.__init__(self, *args, **kwargs) self.status_code = 403 +class HttpResponseNotAllowed(HttpResponse): + def __init__(self, permitted_methods): + HttpResponse.__init__(self) + self['Allow'] = ', '.join(permitted_methods) + self.status_code = 405 + class HttpResponseGone(HttpResponse): def __init__(self, *args, **kwargs): HttpResponse.__init__(self, *args, **kwargs) diff --git a/docs/request_response.txt b/docs/request_response.txt index 33e5ef4d84..4939cac76f 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -400,6 +400,10 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in ``HttpResponseForbidden`` Acts just like ``HttpResponse`` but uses a 403 status code. +``HttpResponseNotAllowed`` + Like ``HttpResponse``, but uses a 405 status code. Takes a single, + required argument: a list of permitted methods (e.g. ``['GET', 'POST']``). + ``HttpResponseGone`` Acts just like ``HttpResponse`` but uses a 410 status code.