DocumentTemplate is a Python library implementing the Document Templating Markup Language (DTML), originally developed for the Zope application server. It allows for dynamic generation of HTML, XML, or other text documents using a tag-based templating system. The current version is 5.3, with releases typically tied to bug fixes or Python version compatibility updates.
pip install documenttemplateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a DTML template string, prepare a context dictionary, and render the template using the `HTML` class. It includes examples of variable substitution, conditional logic (`dtml-if`), and accessing nested context data like environment variables.
Update your code to call `template.render(**context)` instead of `template(**context)`. Ensure all arguments are passed as keywords.
Upgrade your Python environment to Python 3.10 or a newer compatible version (e.g., 3.11, 3.12).
Update any environment variables used for DocumentTemplate configuration by removing the `DT_` prefix.
Always refer to the official DocumentTemplate documentation or Zope DTML references for correct syntax and features. Avoid assuming similarities with other templating engines.
For DocumentTemplate 5.0+, use the `render()` method: `template.render(**context)`.
Ensure that your context dictionary includes a key matching the variable name. For nested access (e.g., `request.user.name`), verify all intermediate keys exist in the context.
Review your template source to ensure all block-level DTML tags have their matching closing tags. Pay close attention to spelling and capitalization.