diff options
author | Simon Law <simon.law@ecometrica.com> | 2012-07-25 13:16:51 -0400 |
---|---|---|
committer | Simon Law <simon.law@ecometrica.com> | 2012-07-25 13:16:51 -0400 |
commit | 68215e393d65eb8999fd3c26566cd7a331fe4300 (patch) | |
tree | e13ca06f327c0581bffbba4cf3e9ba735c364556 /wkhtmltopdf | |
parent | 5a1847309e7fa431c98565805d88a21a40d01406 (diff) | |
download | django-wkhtmltopdf-68215e393d65eb8999fd3c26566cd7a331fe4300.tar.gz django-wkhtmltopdf-68215e393d65eb8999fd3c26566cd7a331fe4300.tar.bz2 django-wkhtmltopdf-68215e393d65eb8999fd3c26566cd7a331fe4300.zip |
settings.WKHTMLTOPDF_ENV can override environment variables.
This is most usefully set to {'DISPLAY': ':1'} in production. This
allows wkhtmltopdf access to a specific X headless server, since the
server will not be running under X.
Diffstat (limited to 'wkhtmltopdf')
-rw-r--r-- | wkhtmltopdf/utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 69da74f..3172c42 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -3,6 +3,7 @@ from __future__ import absolute_import from copy import copy from itertools import chain from os import fdopen +import os import sys from tempfile import mkstemp import urllib @@ -74,12 +75,16 @@ def wkhtmltopdf(pages, output=None, **kwargs): options = copy(options) options.update(kwargs) + env = getattr(settings, 'WKHTMLTOPDF_ENV', None) + if env is not None: + env = dict(os.environ, **env) + cmd = getattr(settings, 'WKHTMLTOPDF_CMD', 'wkhtmltopdf') args = list(chain([cmd], _options_to_args(**options), list(pages), [output])) - return check_output(args, stderr=sys.stderr) + return check_output(args, stderr=sys.stderr, env=env) def template_to_temp_file(template_name, dictionary=None, context_instance=None): |