def get(self, request, *args, **kwargs):
obj = self.get_object()
if obj in request.user.myproducts.products.all():
filepath = os.path.join(settings.PROTECTED_ROOT, obj.media.path)
guessed_type = guess_type(filepath)[0]
wrapper = FileWrapper(file(filepath))
mimetype = 'application/force-download'
if guessed_type:
mimetype = guessed_type
response = HttpResponse(wrapper, content_type='mimetype')
if not request.GET.get("preview"):
response["Content-Disposition"] = "attachment; filename=%s" %(obj.media.name)
response["X-SendFile"] = str(obj.media.name)
return response
else:
raise Http404
评论列表
文章目录