我在Django开发项目中使用wkhtmltopdf时出现以下错误。如果我尝试使用Apache服务器运行它,则返回的状态代码为6而不是1。
任何帮助都将不胜感激。
这是我的视图。命令“['wkhtmltopdf','--disable-javascript','--encoding',u'utf8','--quiet',u'False','/tmp/wkhtmltopdfnUwu3t.html','-']”返回非零退出状态1
class MyPDF(OrgOwnerMixin, PDFTemplateView):
filename = 'my_pdf.pdf'
template_name = 'pdf/test.html'
def get_object(self, *args, **kwargs):
return Organisation.objects.get(slug=self.kwargs['slug'])
def get_context_data(self, *args, **kwargs):
ctx = super(MyPDF, self).get_context_data(*args, **kwargs)
ctx['object'] = self.get_object()
return ctx
以下是Traceback:
Traceback:
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
217. response = self.process_exception_by_middleware(e, request)
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
215. response = response.render()
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/template/response.py" in render
107. self.content = self.rendered_content
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/views.py" in rendered_content
78. cmd_options=cmd_options
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in render_pdf_from_template
186. cmd_options=cmd_options)
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in convert_to_pdf
124. return wkhtmltopdf(pages=filename, **cmd_options)
File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in wkhtmltopdf
110. return check_output(ck_args, **ck_kwargs)
File "/usr/lib/python2.7/subprocess.py" in check_output
574. raise CalledProcessError(retcode, cmd, output=output)
Exception Type: CalledProcessError at /pdf/org-1/
Exception Value: Command '['wkhtmltopdf', '--disable-javascript', '--encoding', u'utf8', '--quiet', u'False', '/tmp/wkhtmltopdfEG5K8j.html', '-']' returned non-zero exit status 1
任何帮助都将不胜感激。
wget
和pathced QT
重新安装wkhtmltopdf
, 而不是使用apt get
,然后在选项中包含--allow /tmp
,然后更改我的style.css
文件。我还没有找到原始文件的问题,但更改了格式以使其工作。 - HenryM