【发布时间】:2021-07-19 06:07:58
【问题描述】:
我正在使用 python-docx-template (docxtpl) 生成一个.docx 文件。
有了这些数据:
docente= {
"id":145,
"lugar_de_nacimiento":"Loja",
"fecha_de_nacimiento":"1973-04-14",
"ciudad":"Loja",
"foto_web_low":"https://sica.utpl.edu.ec/media/uploads/docentes/fotos/web/low/1102904313_low.jpg"
}
我有一个函数,我将图像docente['foto_web_low'] 传递给context 和模板的路径:
from docxtpl import DocxTemplate, InlineImage
from docx.shared import Mm
def generaraDocumento(request):
response = HttpResponse(content_type='application/msword')
response['Content-Disposition'] = 'attachment; filename="cv.docx"'
doc = DocxTemplate(str(settings.BASE_DIR) + '/cv_api/templates/docx_filename.docx')
imagen = docente['foto_web_low']
context = {'imagen': imagen}
doc.render(context)
doc.save(response)
return response
我想要显示的图像的模板docx_filename.docx 有这个:
我有要显示的数据的模板docx_filename.docx 有这个:
Image: {{ imagen }}
生成文档时,我只得到 URL 地址而不是图像,在我的模板中它返回:
Image: https://sica.utpl.edu.ec/media/uploads/docentes/fotos/web/low/1102904313_low.jpg
如何使图像出现在文档.docx (docxtpl) 中。提前致谢。
【问题讨论】:
标签: python django image templates python-docx