![](/img/trans.png)
[英]wkhtmltopdf exited with non-zero code {0} django html to pdf on server
[英]Generating pdf with wkhtmltopdf Django
我正在尝试用这个库创建一个pdf,实现最简单的de docs示例
使用url并直接从模板中渲染,就像这样
url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
filename='my_pdf.pdf'), name='pdf'),
这是模板文件的html
<!DOCTYPE html>
<html>
<head>
<title>Hello Wold</title>
</head>
<body>
<p>My First Pdf</p>
</body>
</html>
但是当我尝试网址时,错误就是这个
/ pdf /'NoneType'对象的AttributeError没有属性'endswith'
我该怎么办呢
这是Traceback
回溯:get_response中的文件“/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py”139. response = response.render()文件“/ usr / local / lib / python2 .7 / dist-packages / django / template / response.py“in render 105. self.content = self.rendered_content File”/usr/local/lib/python2.7/dist-packages/wkhtmltopdf/views.py“in rendered_content 123. delete =(not debug)文件“/usr/local/lib/python2.7/dist-packages/wkhtmltopdf/views.py”在render_to_temporary_file中78. content = make_absolute_paths(content)文件“/ usr / local / lib make_absolute_paths 151中的/python2.7/dist-packages/wkhtmltopdf/utils.py“。如果不是x ['root']。endswith('/'):
异常类型:/ false / = / pdf / Exception值:'NoneType'对象没有属性'endswith'
环境:
请求方法:GET
Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'rest_framework',
'cian',
'django_extensions',
'wkhtmltopdf')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
这是django-wkhtmltopd错误的屏幕截图
发生此错误的原因是wkhtmltopdf使用settings.py的STATIC_ROOT中的路径生成pdf文件。 尝试为STATIC_ROOT分配值并进行测试。
STATIC_ROOT = 'path.to.your.static.directory'
您的根路径似乎有问题。 尝试在Django设置文件(settings.py)中设置STATIC_URL
错误是我没有在settings.py中定义我的media_root和media_url,包装器期望你有static_root,media_root,static_url和media_url可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.