Skip to content

Commit

Permalink
Fixed #2185 -- Changed django.views.decorators.http.require_http_meth…
Browse files Browse the repository at this point in the history
…ods decorator to use HttpResponseNotAllowed instead of HttpResponseForbidden

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3163 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Jun 20, 2006
1 parent 551a027 commit a09682f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions django/views/decorators/http.py
Expand Up @@ -4,26 +4,26 @@


from django.utils.decorators import decorator_from_middleware from django.utils.decorators import decorator_from_middleware
from django.middleware.http import ConditionalGetMiddleware from django.middleware.http import ConditionalGetMiddleware
from django.http import HttpResponseForbidden from django.http import HttpResponseNotAllowed


conditional_page = decorator_from_middleware(ConditionalGetMiddleware) conditional_page = decorator_from_middleware(ConditionalGetMiddleware)


def require_http_methods(request_method_list): def require_http_methods(request_method_list):
""" """
Decorator to make a view only accept particular request methods. Usage:: Decorator to make a view only accept particular request methods. Usage::
@require_http_methods(["GET", "POST"]) @require_http_methods(["GET", "POST"])
def my_view(request): def my_view(request):
# I can assume now that only GET or POST requests make it this far # I can assume now that only GET or POST requests make it this far
# ... # ...
Note that request methods ARE case sensitive. Note that request methods ARE case sensitive.
""" """
def decorator(func): def decorator(func):
def inner(request, *args, **kwargs): def inner(request, *args, **kwargs):
method = request.META.get("REQUEST_METHOD", None) method = request.META.get("REQUEST_METHOD", None)
if method not in request_method_list: if method not in request_method_list:
raise HttpResponseForbidden("REQUEST_METHOD '%s' not allowed" % method) return HttpResponseNotAllowed(request_method_list)
return func(request, *args, **kwargs) return func(request, *args, **kwargs)
return inner return inner
return decorator return decorator
Expand Down

0 comments on commit a09682f

Please sign in to comment.