summaryrefslogtreecommitdiff
path: root/django/views/decorators
diff options
context:
space:
mode:
Diffstat (limited to 'django/views/decorators')
-rw-r--r--django/views/decorators/csrf.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/django/views/decorators/csrf.py b/django/views/decorators/csrf.py
index 92771c56df..4b8b8804b0 100644
--- a/django/views/decorators/csrf.py
+++ b/django/views/decorators/csrf.py
@@ -1,5 +1,7 @@
from functools import wraps
+from asgiref.sync import iscoroutinefunction
+
from django.middleware.csrf import CsrfViewMiddleware, get_token
from django.utils.decorators import decorator_from_middleware
@@ -51,9 +53,17 @@ def csrf_exempt(view_func):
# view_func.csrf_exempt = True would also work, but decorators are nicer
# if they don't have side effects, so return a new function.
- @wraps(view_func)
- def wrapper_view(*args, **kwargs):
- return view_func(*args, **kwargs)
- wrapper_view.csrf_exempt = True
- return wrapper_view
+ if iscoroutinefunction(view_func):
+
+ async def _view_wrapper(request, *args, **kwargs):
+ return await view_func(request, *args, **kwargs)
+
+ else:
+
+ def _view_wrapper(request, *args, **kwargs):
+ return view_func(request, *args, **kwargs)
+
+ _view_wrapper.csrf_exempt = True
+
+ return wraps(view_func)(_view_wrapper)