How to set django upload_handler in admin?

I am trying to create a django loading progress indicator in django admin. The application is only a small part of the project, so I do not want to install a custom download handler in settings.py.

Load_handler can be set using request.upload_handlers.insert(0, UploadProgressHandler(request)) , but not inside the add_view of the admin django class. The answer is an exception:

If you try to change request.upload_handlers after reading from request.POST or request.FILES, Django will throw an error.

I also tried to do this using a decorator over add_view , but then I don't know how to access request.upload_handlers .

Can someone help me?

+6
python django django-admin file-upload
source share
1 answer

Look at the source for the decorator that comes with the admin application:

 def staff_member_required(view_func): """ Decorator for views that checks that the user is logged in and is a staff member, displaying the login page if necessary. """ @wraps(view_func) def _checklogin(request, *args, **kwargs): if request.user.is_active and request.user.is_staff: # The user is valid. Continue to the admin page. return view_func(request, *args, **kwargs) 

The decorator wraps the original view, so you can check the arg of the request before calling it with the fun function.

+1
source share

All Articles