aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wkhtmltopdf/utils.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py
index 413a343..3bfa61a 100644
--- a/wkhtmltopdf/utils.py
+++ b/wkhtmltopdf/utils.py
@@ -85,11 +85,12 @@ def render_to_pdf(template_name, dictionary=None, context_instance=None, header_
def template_to_temp_file(*args, **kwargs):
- """Renders a template to a temp file, and returns the path of the file."""
- fd, tmppath = mkstemp(suffix='.html')
- f = fdopen(fd, 'wt')
- f.write(smart_str(loader.render_to_string(*args, **kwargs)))
- f.close()
- return tmppath
+ """
+ Renders a template to a temp file, and returns the path of the file.
+ """
+ file_descriptor, tempfile_path = mkstemp(suffix='.html')
+ with fdopen(file_descriptor, 'wt') as f:
+ f.write(smart_str(loader.render_to_string(*args, **kwargs)))
+ return tempfile_path