如何将Django模型ImageField添加到ReportLab

问题描述

我想将媒体文件添加到Reportlab生成的PDF中。

STATIC_ROOT = os.path.join(BASE_DIR,"staticfiles")
output STATIC_ROOT --> project/static/

MEDIA_ROOT = os.path.join(BASE_DIR,"media")
output STATIC_ROOT --> project/media/

当我绘制静态图像时就可以了:

logo = STATIC_ROOT + "img/dilains-logotipo-bg-white-290x100.jpg"
self.canvas.drawImage(logo,self.x,self.y,w,h,preserveAspectRatio=True)

但使用媒体:

output self.rejection.img_general_model_1 --> images/treatments/rejections/mouth.jpg
picture = MEDIA_ROOT + str(self.rejection.img_general_model_1)
self.canvas.drawImage(picture,self.x + text_x * 0,preserveAspectRatio=True,mask='auto')

抛出错误

Cannot open resource "/project/media/images/treatments/rejections/mouth.jpg"
<class 'OSError'>

有人知道如何解决它? 并在生产中使用AWS S3配置?

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)