Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How does python docx-template work with jinja2?


Asked by Adaline Lewis on Dec 06, 2021 FAQ



By using these tags, python-docx-template will take care to put the real jinja2 tags at the right place into the document’s xml source code. In addition, these tags also tell python-docx-template to remove the paragraph, table row, table column or run where the begin and ending tags are located and only takes care about what is in between.
Similarly,
Jinja2 supports putting often used code into macros. These macros can go into different templates and get imported from there. This works similarly to the import statements in Python. It’s important to know that imports are cached and imported templates don’t have access to the current template variables, just the globals by default.
Indeed, A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine. A template contains variables and/or expressions, which get replaced with values when a template is rendered; and tags, which control the logic of the template. The template syntax is heavily inspired by Django and Python.
Additionally,
Python Jinja module Jinja is a template engine for Python. It is similar to the Django template engine. A template engine or template processor is a library designed to combine templates with a data model to produce documents.
Likewise,
As the Jinja2 package is used, one can use all jinja2 tags and filters inside the word document. Nevertheless there are some restrictions and extensions to make it work inside a word document: The usual jinja2 tags, are only to be used inside the same run of a same paragraph, it can not be used across several paragraphs, table rows, runs.