Mako is a hyperfast and lightweight templating language for Python, designed to be both powerful and easy to use. The current version is 1.3.10, released on March 28, 2026. Mako follows a regular release cadence, with updates addressing bugs and improvements.
pip install makoVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a template lookup, load a template, and render it with variables using Mako.
Upgrade your Python environment to version 3.7 or later.
Avoid using 'import="*"' in <%namespace> tags to maintain optimal performance.
Ensure the template file exists and that the mako.lookup.TemplateLookup object is initialized with the correct 'directories' parameter pointing to the template's location.
Ensure the template file exists at the specified path and that Mako's `TemplateLookup` object is correctly initialized with the directory containing the template.
Ensure all variables used in the template are passed in the dictionary to `template.render()`. For clearer debugging, initialize `Template` or `TemplateLookup` with `strict_undefined=True` to get specific `NameError` messages including the variable name.
Install Mako using pip: `pip install mako`. Verify that the correct Python environment's pip is used for installation.
Carefully review the Python code within template blocks for syntax correctness (e.g., missing colons, incorrect indentation). If Mako tags are intended as literal text, escape them (e.g., write `<%%` for `<%`).
Explicitly pass the expected variable to the template's rendering context or check for its existence (e.g., `if var is not UNDEFINED:`) before attempting to call methods or access attributes. Alternatively, initialize `Template` or `TemplateLookup` with `strict_undefined=True` to raise a `NameError` for missing variables sooner.
Verify that the `directories` argument passed to `TemplateLookup` correctly points to the location of your template files and that the URI used in `<%include>` or `<%inherit>` tags is correct and relative to those directories.