Fixed #33172 -- Added example of modifying upload handlers on the fly for CBVs.

This commit is contained in:
sreehari1997 2021-10-12 13:39:29 +05:30 committed by Mariusz Felisiak
parent 86971c4090
commit e2f778d579
1 changed files with 21 additions and 0 deletions

View File

@ -271,3 +271,24 @@ list::
@csrf_protect @csrf_protect
def _upload_file_view(request): def _upload_file_view(request):
... # Process 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