【发布时间】:2014-01-30 09:29:47
【问题描述】:
我指的是https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ 用于使用 reportlab 生成 pdf。
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")
# Close the PDF object cleanly, and we're done.
logging.debug('-----p---')
logging.debug(p)
p.showPage()
p.save()
return response
如果我在 myapp 中添加此 reportlab 文件夹,则会出现此错误:
ViewDoesNotExist at /aps/print-pdf/
Could not import myapp.views. Error was: No module named reportlab
如果我将此 reportlab 文件夹从 myapp 文件夹中取出,则会出现此错误:
ViewDoesNotExist at /aps/print-pdf/
Tried some_view in module myapp.views. Error was: 'HardenedModulesHook' object has no attribute '_files'
这有什么问题?请帮忙。
【问题讨论】:
-
你是如何安装reportlab的?你使用 virtualenv 吗?
标签: python django pdf django-views pdf-generation