如何在管理中设置django upload_handler?
我正在尝试在 django 管理中制作 django 上传进度条。 该应用程序只是项目的一小部分,因此我不想在 settings.py 中设置自定义上传处理程序。
upload_handler 可以使用 request.upload_handlers.insert(0, UploadProgressHandler(request)) 设置,但不能在 django 管理类的 add_view 中设置。 响应是这样的异常:
如果您在读取后尝试修改request.upload_handlers request.POST 或 request.FILES Django 将抛出错误。
我还尝试在 add_view
上使用装饰器来执行此操作,但后来我不知道如何访问 request.upload_handlers
。
有人可以帮我吗?
I'm trying to make a django upload progress bar within the django admin.
The application is only a small part of the project, therefor I do not want to set the custom upload handler in the settings.py.
The upload_handler can be set with request.upload_handlers.insert(0, UploadProgressHandler(request))
but not within the add_view of the django admin class.
The response is this exception:
If you try to modify request.upload_handlers after reading from
request.POST or request.FILES Django will throw an error.
I also tried doing this with a decorator over the add_view
but then I do not know how to access the request.upload_handlers
.
Can someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下管理应用程序附带的装饰器的源代码:
装饰器“包装”原始视图,以便您可以在调用原始视图函数之前检查请求参数。
Have a look at the source for the decorator that comes with the admin app:
The decorator 'wraps' the original view so you are able to check the request arg before calling the original view func with it.