from docxtpl import DocxTemplate
DEST_FILE = 'templates\\output\\header_footer_image.docx'
tpl = DocxTemplate('templates\\header_footer_image_tpl.docx')
#替换字符串
context = {
'mycompany': 'The World Wide company',
}
#替换图片
tpl.replace_media('templates\\dummy_pic_for_header.png', 'templates\\python.png')
tpl.render(context)
tpl.save(DEST_FILE)