aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'wkhtmltopdf/views.py')
-rw-r--r--wkhtmltopdf/views.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py
index 5a46490..92e2d0f 100644
--- a/wkhtmltopdf/views.py
+++ b/wkhtmltopdf/views.py
@@ -5,7 +5,6 @@ from tempfile import NamedTemporaryFile
from django.conf import settings
from django.http import HttpResponse
from django.template.response import TemplateResponse
-from django.utils.encoding import smart_str
from django.views.generic import TemplateView
from .utils import (content_disposition_filename, make_absolute_paths,
@@ -74,15 +73,21 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse):
context = self.resolve_context(self.context_data)
- content = smart_str(template.render(context))
+ content = template.render(context)
content = make_absolute_paths(content)
- tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize,
- suffix=suffix, prefix=prefix,
- dir=dir, delete=delete)
+ try:
+ tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize,
+ suffix=suffix, prefix=prefix,
+ dir=dir, delete=delete)
+ except TypeError:
+ # Python 3 has 'buffering' arg for 'NamedTemporaryFile' class
+ tempfile = NamedTemporaryFile(mode=mode, buffering=bufsize,
+ suffix=suffix, prefix=prefix,
+ dir=dir, delete=delete)
try:
- tempfile.write(content)
+ tempfile.write(content.encode('utf-8'))
tempfile.flush()
return tempfile
except: