z3c.pt

raw JSON →
5.1 verified Mon Apr 27 auth: no python

Fast Zope Page Templates (ZPT) engine implementing TAL/TALES/METAL specifications. Version 5.1 requires Python >=3.9. Releases are stable and infrequent, focusing on maintenance.

pip install z3c.pt
error ImportError: cannot import name 'PageTemplate' from 'z3c.pt'
cause Older version of z3c.pt (<5.0) might have different API, or package not installed correctly.
fix
Install latest version: pip install --upgrade z3c.pt. Ensure you are using Python >=3.9.
error RuntimeError: No engine configured
cause Engine not created before compiling templates. The default engine must be obtained via getEngine().
fix
Call getEngine() at module level or before compiling templates: from z3c.pt import getEngine; engine = getEngine()
breaking In version 5.0, the package was split from `z3c.pt` standalone; previously it was part of `z3c.template`. If upgrading from older versions (pre-5.0), imports and API changed. Ensure you are using `z3c.pt` directly.
fix Update imports from e.g. `z3c.template` to `z3c.pt` and adjust API usage per current docs.
deprecated The `z3c.pt` package now requires Python 3.9+. Python 2.7 and 3.5-3.8 are no longer supported.
fix Upgrade to Python 3.9 or later.
gotcha TAL expressions like `tal:content` expect Python expressions, not paths. A common mistake is using dotted paths like `tal:content="context/some"` which is Zope-specific. For standalone use, provide a dict with keys as variable names.
fix Use simple Python expressions in TAL attributes, e.g., `tal:content="variable"`.

Compiles a ZPT template string and renders it with a context dictionary.

from z3c.pt import PageTemplate, getEngine
engine = getEngine()
template = engine.compile('<html><body><p tal:content="message"></p></body></html>')
# For a simple render, use the template directly (requires context)
# engine = engine  # no context needed for compile, but rendering needs dict
result = template({'message': 'Hello, world!'})
print(result)