0

我想在浏览器中打印 pdf 文件以供选择保存。我在 django 2.0.2 中使用 weasyprint

我在我的views.py中使用了这个代码,但是firefox自动下载它并且不介意“内联”。有什么帮助吗?

response['Content-Disposition'] = 'inline; filename="gene_detail_description_print.pdf"'
4

1 回答 1

0

请看这里:https ://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

从那里复制:

HTTP 上下文中的第一个参数是 inline(默认值,表示它可以显示在网页内,或作为网页)或附件(表示应该下载它;大多数浏览器显示“另存为”对话框,预填充文件名参数的值(如果存在)。

Content-Disposition: inline
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"

所以你应该使用response['Content-Disposition'] = 'attachment; filename="gene_detail_description_print.pdf"'允许用户下载文件并可能重命名它。

于 2018-03-28T16:22:49.177 回答