1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | def method_required(method):
"""
Decorator factory that limits a view to a particular HTTP method.
"""
from django.http import HttpResponseNotAllowed
def _decorator(func):
def _closure(request, *args, **kwargs):
if not request.method==method:
return HttpResponseNotAllowed([method])
else:
return func(request, *args, **kwargs)
_closure.__name__ = func.__name__
_closure.__doc___ = func.__doc__
_closure.__module___ = func.__module__
return _closure
return _decorator
|
More like this
- PK->objects in view signature by AdamKG 5 years, 1 month ago
- Simple Exception Response for AJAX debugging by newmaniese 5 years, 2 months ago
- Cookieless Session Decorator by achimnol 3 years, 9 months ago
- require XMLHttpRequest view decorator by skam 5 years, 3 months ago
- Decorator that limits request methods by schinckel 3 years, 10 months ago
Comments
Django already has decorators that do this... see here for some notes.
#