我正在尝试使用这个库创建一个 pdf,实现最简单的 de docs 示例
使用 url 并像这样直接从模板渲染
url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
filename='my_pdf.pdf'), name='pdf'),
Run Code Online (Sandbox Code Playgroud)
这是模板文件的html
<!DOCTYPE html>
<html>
<head>
<title>Hello Wold</title>
</head>
<body>
<p>My First Pdf</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试 url 时,错误是这样的
/pdf/ 'NoneType' 对象的 AttributeError 没有属性 'endswith'
我该如何解决
这是回溯
回溯:get_response 139 中的文件“/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py”。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 render_content 123. delete=(not debug) file "/usr/local/lib/python2.7/dist-packages/wkhtmltopdf/views.py" in render_to_temporary_file 78. content = make_absolute_paths(content) File "/usr/local/lib /python2.7/dist-packages/wkhtmltopdf/utils.py" in make_absolute_paths 151. 如果不是 x['root'].endswith('/'):
异常类型:/pdf/ 处的 AttributeError 异常值:“NoneType”对象没有“endswith”属性
环境:
请求方式:GET
Django …Run Code Online (Sandbox Code Playgroud)