【发布时间】:2021-12-02 05:35:28
【问题描述】:
我正在尝试将图像添加到 Reportlab 中生成的 PDF。我正在尝试从 Django 字段访问图像,并指定文件的完整路径。
当我运行以下代码时,我得到:“异常值:getKeepWithNext”。
任何关于我做错了什么的帮助将不胜感激。
def holding_pdf(self, course_slug, holding_slug):
buffer = io.BytesIO()
holding = HoldingDetail.objects.get(identifier=holding_slug)
doc = SimpleDocTemplate(buffer,
rightMargin=72,
leftMargin=72,
topMargin=72,
bottomMargin=72,
pagesize=A4,
title=f"Why the {holding.name} is in the portfolio.pdf")
elements = []
styles = getSampleStyleSheet()
elements.append(Paragraph(str(holding.logo.path), styles['Normal']))
elements.append(Image(holding.logo.path))
print(holding.logo.path)
doc.build(elements)
buffer.seek(0)
return FileResponse(buffer, as_attachment=False, filename=f"Why the {holding.name} is in the portfolio.pdf")
【问题讨论】:
-
你能发布更多关于异常的信息吗?
-
AttributeError at /leads/investsense-hub24/why/ETL0484AU/pdf/getKeepWithNext 请求方法:GET 请求 URL:localhost:8000/leads/investsense-hub24/why/ETL0484AU/pdf Django 版本:3.2.9 异常类型:AttributeError 异常值:getKeepWithNext 异常位置: C:\Users\danie\Python\Django\PortfolioSense\env\lib\site-packages\PIL\Image.py,第 546 行,在 getattr Python 可执行文件:C:\Users\danie\ Python\Django\PortfolioSense\env\Scripts\python.exe Python 版本:3.8.5