python - 在 Django 提供的 IFrame 中显示 PDF 时,IE 8 崩溃

标签 python django apache internet-explorer

我有一个在 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/

相关文章:

linux - 以 apache 所有者身份授予文件夹权限

Python 3 - 验证 sendto() 成功

python - Django - 黑客尝试,[Django] 错误 : Invalid HTTP_HOST header

apache - 日志中的 HTTP 状态代码 103

python - 无法使用 Nose 测试运行测试

javascript - 在 Django 中使用 Ajax 的问题

apache - 为什么apache虚拟服务器没有运行

python - 获取单元格的行和列,xlwings UDF在哪里被调用?

python - 具有外部数据库的 Sqlite 更新 Hook

python - 相当于 numpy.unique 的 2D