Skip to content

Commit 08a5d74

Browse files
authored
Merge pull request #593 from aperechnev/master
Possibility to skip missing pictures
2 parents b97fa32 + 97df786 commit 08a5d74

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docxtpl/template.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, template_file: Union[IO[bytes], str, PathLike]) -> None:
4646
self.docx = None
4747
self.is_rendered = False
4848
self.is_saved = False
49+
self.allow_missing_pics = False
4950

5051
def init_docx(self, reload: bool = True):
5152
if not self.docx or (self.is_rendered and reload):
@@ -797,10 +798,11 @@ def _replace_pics(self):
797798
if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER):
798799
self._replace_docx_part_pics(rel.target_part, replaced_pics)
799800

800-
# make sure all template images defined by user were replaced
801-
for img_id, replaced in replaced_pics.items():
802-
if not replaced:
803-
raise ValueError("Picture %s not found in the docx template" % img_id)
801+
if not self.allow_missing_pics:
802+
# make sure all template images defined by user were replaced
803+
for img_id, replaced in replaced_pics.items():
804+
if not replaced:
805+
raise ValueError("Picture %s not found in the docx template" % img_id)
804806

805807
def get_pic_map(self):
806808
return self.pic_map

0 commit comments

Comments
 (0)