From a9e1c24ea0f810863c4d611148c41a24afe4ec62 Mon Sep 17 00:00:00 2001 From: George Hickman Date: Mon, 21 May 2012 15:52:38 +0100 Subject: Only set 'Content-Disposition' header if filename is set Setting 'Content-Disposition' explicitly sets the PDF as an attachment causing browsers to download the PDF. However newer browsers, like Chrome, will display the PDF without this header. So assume the dev wants this to be force download if they set the filename. --- wkhtmltopdf/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index cf141ee..36efaf5 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -11,9 +11,11 @@ from wkhtmltopdf.utils import template_to_temp_file, wkhtmltopdf class PDFResponse(HttpResponse): - def __init__(self, content, filename): + def __init__(self, content, **kwargs): super(PDFResponse, self).__init__(content, 'application/pdf') - self.__setitem__('Content-Disposition', 'attachment; filename=%s' % filename) + if 'filename' in kwargs: + header_content = 'attachment; filename={0}'.format(kwargs.get('filename')) + self.__setitem__('Content-Disposition', header_content) class PdfResponse(PDFResponse): -- cgit v1.2.3