summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsreehari1997 <sreeharivijayan619@gmail.com>2021-10-12 13:39:29 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-18 10:25:55 +0200
commitc067a2b68fe2701608b34ac4a538e1f9dba0e9f2 (patch)
treef70e90a336146018ef283b1d9c69532564d655a8
parent00aa3e0b9b8fac8fa5adab47249790d2ee2f767e (diff)
[4.0.x] Fixed #33172 -- Added example of modifying upload handlers on the fly for CBVs.
Backport of e2f778d57947d168a875159e6df075255eea4bbc from main
-rw-r--r--docs/topics/http/file-uploads.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt
index ca272d785a..c946662bba 100644
--- a/docs/topics/http/file-uploads.txt
+++ b/docs/topics/http/file-uploads.txt
@@ -271,3 +271,24 @@ list::
@csrf_protect
def _upload_file_view(request):
... # Process request
+
+ If you are using a class-based view, you will need to use
+ :func:`~django.views.decorators.csrf.csrf_exempt` on its
+ :meth:`~django.views.generic.base.View.dispatch` method and
+ :func:`~django.views.decorators.csrf.csrf_protect` on the method that
+ actually processes the request. Example code::
+
+ from django.utils.decorators import method_decorator
+ from django.views import View
+ from django.views.decorators.csrf import csrf_exempt, csrf_protect
+
+ @method_decorator(csrf_exempt, name='dispatch')
+ class UploadFileView(View):
+
+ def setup(self, request, *args, **kwargs):
+ request.upload_handlers.insert(0, ProgressBarUploadHandler(request))
+ super().setup(request, *args, **kwargs)
+
+ @method_decorator(csrf_protect)
+ def post(self, request, *args, **kwargs):
+ ... # Process request