The propeller is {{tag_1}} for spicy food {{tag_2}}.
The propeller is {{tag_1}} for spicy food {{tag_2}}
from docxtpl import DocxTemplate
# With old docxtpl version, "... for spicy ..." was replaced by "... forspicy..."
# This test is for checking that is some cases the spaces are not lost anymore
tpl = DocxTemplate('templates\\preserve_spaces_tpl.docx')
tags = ['tag_1', 'tag_2']
replacement = ['looking', 'too']
context = dict(zip(tags, replacement))
#也可以以下面的形式
#context = {'tag_1': 'looking', 'tag_2': 'too'}
tpl.render(context)
tpl.save('templates\\output\\preserve_spaces.docx')
The propeller is looking for spicy food too.
The propeller is looking for spicy food too.