我有一个在 IFrame 中显示 pdf 的 Web 应用程序。我最近进行了更改,开始使用 Django 提供 PDF,而不是允许 Apache 提供 PDF。最初,我使用FileWrapper approach返回文件。这在所有浏览器上都运行良好,除了 IE 8 崩溃(可能是其他版本的 IE,没有测试)。
我想出了如何解决这个问题,但解决起来有点痛苦,所以我在这里发布答案。
最佳答案
解决方案是将 mod_xsendfile 用作 suggested in this post进行以下调整:
mimeType,_ = mimetypes.guess_type(filePath)
response = django.http.HttpResponse(mimetype = mimeType)
response['Accept-Ranges'] = 'bytes'
response['X-Sendfile'] = filePath
return response
除了能够正确使用 IE/iframe 之外,它还允许恢复文件下载。
关于python - 在 Django 提供的 IFrame 中显示 PDF 时,IE 8 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4926355/