Registry / web-framework / zope-pagetemplate

zope-pagetemplate

JSON →
library6.1pypypi✓ verified 84d ago

Zope Page Templates (ZPT) is a powerful templating system for Python, renowned for its ability to allow designers to work directly with templates using standard XML/HTML tools. Templates are valid XML/HTML documents, making them easy to edit in visual editors. It is currently at version 6.1, actively maintained by the Zope Foundation, with updates typically coinciding with other Zope-related library releases.

pip install zope-pagetemplate
INSTALL
IMPORT
SIG · ZOPE-PAGETEMPLATE
Z
zope-pagetemplate
web-frameworkpythonv6.1
Install
4.2s avg
Import
200ms
Disk
39MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.207s · 36MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.2s · import 0.194s · 37MB
39MB installed
● package 39MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PageTemplate
from zope.pagetemplate.pagetemplate import PageTemplate
TALInterpreter
from zope.pagetemplate.tal import TALInterpreter
from zope.tal import TALInterpreter
Since v5.0, zope.tal and zope.tales are integrated into zope.pagetemplate.

This quickstart demonstrates how to define a Zope Page Template, create a Python object to serve as the template's context, and render the template, substituting dynamic data using TAL (Template Attribute Language) expressions.

from zope.pagetemplate.pagetemplate import PageTemplate template_str = """ <html xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title tal:content="context/title">Default Title</title> </head> <body> <h1 tal:content="context/header"></h1> <p tal:content="context/message">Default Message</p> <ul tal:repeat="item context/items"> <li tal:content="item"></li> </ul> </body> </html> """ # Simulate a context object for the template class Context: def __init__(self, title, header, message, items): self.title = title self.header = header self.message = message self.items = items context_data = Context( title="My Dynamic Page", header="Welcome to ZPT!", message="This content is dynamically rendered.", items=["item 1", "item 2", "item 3"] ) # Create a PageTemplate instance with the template string template = PageTemplate(text=template_str) # Render the template with the provided context output = template(context=context_data) print(output)
Debug
Known issues
breakingZope Page Templates version 6.x (including 6.1) requires Python 3.10 or newer. Older Python versions are no longer supported.
fix
Ensure your project is running on Python 3.10 or a more recent compatible version. For older Python environments, use zope.pagetemplate < 6.0.
affects: 6.0+
breakingThe previously separate `zope.tal` and `zope.tales` packages have been integrated into `zope.pagetemplate` since version 5.0. Direct imports from the standalone `zope.tal` or `zope.tales` packages will fail.
fix
Update your import statements to use `from zope.pagetemplate.tal import ...` or `from zope.pagetemplate.tales import ...`.
affects: 5.0+
gotchaZope Page Templates are strict about XML well-formedness. Minor HTML parsing errors (e.g., unclosed tags, incorrect nesting, invalid character entities) will prevent templates from rendering and raise `zope.pagetemplate.markup.xmlfile.ZPTParseError`.
fix
Always validate your templates for XML/HTML correctness. Ensure all tags are properly closed and nested. Tools like `lxml.html` can sometimes help clean up 'tag soup' HTML before passing it to ZPT.
affects: All versions
gotchaUnderstanding the ZPT context mechanism (`context/attribute`, `repeat`, `define`, `default`) is crucial. Misinterpreting how context objects and their attributes are exposed often leads to `KeyError` or `AttributeError` during template evaluation.
fix
Familiarize yourself with the ZPT/TAL specification regarding context lookup. Ensure the context object passed to the template rendering call (`template(context=...)`) provides all expected attributes or items that TAL expressions are attempting to access.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name 'TALInterpreter' from 'zope.tal'
The `zope.tal` and `zope.tales` packages were merged into `zope.pagetemplate` in version 5.0.
fix
Change your import statement to `from zope.pagetemplate.tal import TALInterpreter`.
zope.pagetemplate.markup.xmlfile.ZPTParseError: <string> Line X, Column Y: ...
The template provided is not well-formed XML/HTML, or contains syntax errors that ZPT's parser cannot handle.
fix
Review the template string at the indicated line and column for unclosed tags, incorrect nesting, invalid character entities, or other XML syntax violations. ZPT requires strict XML compliance.
AttributeError: 'ContextObject' object has no attribute 'some_variable'
The TAL expression `context/some_variable` attempts to access an attribute that does not exist on the context object provided during rendering.
fix
Ensure that the object passed as `context` to `template()` has an attribute named `some_variable`. If it's a dictionary, access with `context/key` will also work, but Python objects are more common for attributes.
TypeError: PageTemplate() got an unexpected keyword argument 'source'
Older versions or specific usages might have expected a `source` keyword argument for template content, but the current `PageTemplate` constructor uses `text`, `filename`, or `url`.
fix
Use `template = PageTemplate(text=template_string)` instead of `source`. If loading from a file, use `PageTemplate(filename='path/to/template.pt')`.
Upgrade
Version history
6.1latest on PyPI · released Nov 21, 2025
Audit
Dependencies
zope.interfacerequiredProvides core interface definitions used by ZPT.
zope.locationrequiredProvides object location services, often relevant in Zope-style applications.
zope.publisherrequiredUsed for publishing and HTTP request handling, particularly when integrating with Zope applications.
Agent activity
35 hits · last 30 days
node
31
OpenAI (training)
1
Resources
zope-pagetemplate — pip install zope-pagetemplate · libregistry