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
- require XMLHttpRequest view decorator by skam 4 years ago
- Cookieless Session Decorator by achimnol 2 years, 6 months ago
- LoginRequired class-based view decorator by mjumbe 6 months, 2 weeks ago
- Decorating class-based views by lqc 1 week, 3 days ago
- ID in request GET or POST required decorator by markeyev 1 year, 5 months ago
Comments
Django already has decorators that do this... see here for some notes.
#